Skip to content

Commit

Permalink
Work in progress refactoring to Path system
Browse files Browse the repository at this point in the history
  • Loading branch information
rubendel committed Oct 15, 2015
1 parent 4875b98 commit 0dae54a
Show file tree
Hide file tree
Showing 112 changed files with 568 additions and 1,459 deletions.
39 changes: 13 additions & 26 deletions BimServer/src/org/bimserver/BimServerImporter.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
package org.bimserver;

/******************************************************************************
* Copyright (C) 2009-2015 BIMserver.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
Expand Down Expand Up @@ -54,6 +38,7 @@
import org.bimserver.shared.exceptions.ServiceException;
import org.bimserver.shared.exceptions.UserException;
import org.bimserver.utils.Formatters;
import org.bimserver.utils.PathUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -106,10 +91,10 @@ class Key {
public String comment;
public long userId;
public Date date;
public File file;
public Path file;
public long poid;

public Key(File file, long oid, String comment, Date date, long userId) {
public Key(Path file, long oid, String comment, Date date, long userId) {
this.file = file;
poid = oid;
this.comment = comment;
Expand Down Expand Up @@ -148,7 +133,7 @@ public void start() {
// client.getPluginInterface().setDefaultRenderEngine(renderEnginePluginConfiguration.getOid());
// }
// }
File incoming = new File(path);
Path incoming = Paths.get(path);
final Map<GregorianCalendar, Key> comments = new TreeMap<>();
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss");
for (SProject project : remoteClient.getBimsie1ServiceInterface().getAllProjects(false, false)) {
Expand All @@ -157,11 +142,11 @@ public void start() {
gregorianCalendar.setTime(revision.getDate());
if (!revision.getComment().startsWith("generated for")) {
User user = users.get(revision.getUserId());
File userFolder = new File(incoming, user.getUsername());
Path userFolder = incoming.resolve(user.getUsername());
boolean found = false;
for (File file : userFolder.listFiles()) {
if (file.getName().endsWith(revision.getComment())) {
String dateStr = file.getName().substring(0, 19);
for (Path file : PathUtils.getDirectories(userFolder)) {
if (file.getFileName().toString().endsWith(revision.getComment())) {
String dateStr = file.getFileName().toString().substring(0, 19);
Date parse = dateFormat.parse(dateStr);
GregorianCalendar fileDate = new GregorianCalendar();
fileDate.setTime(parse);
Expand All @@ -187,7 +172,7 @@ public void start() {
@Override
public void run() {
Key key = comments.get(gregorianCalendar);
LOGGER.info("Checking in: " + key.file.getName() + " " + Formatters.bytesToString(key.file.length()));
LOGGER.info("Checking in: " + key.file.getFileName().toString() + " " + Formatters.bytesToString(key.file.toFile().length()));
Project sProject = projects.get(key.poid);
try {
SDeserializerPluginConfiguration desserializer = client.getBimsie1ServiceInterface().getSuggestedDeserializerForExtension("ifc", sProject.getOid());
Expand Down Expand Up @@ -232,6 +217,8 @@ public void run() {
LOGGER.error("", e);
} catch (ParseException e) {
LOGGER.error("", e);
} catch (IOException e) {
LOGGER.error("", e);
}
}

Expand Down
12 changes: 6 additions & 6 deletions BimServerClientLib/src/org/bimserver/client/BimServerClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
*****************************************************************************/

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Path;
import java.util.HashSet;
import java.util.Set;

Expand Down Expand Up @@ -253,9 +253,9 @@ public void registerTokenChangeListener(TokenChangeListener tokenChangeListener)
tokenChangeListeners.add(tokenChangeListener);
}

public long checkin(long poid, String comment, long deserializerOid, boolean merge, boolean sync, File file) throws IOException, UserException, ServerException {
FileInputStream fis = new FileInputStream(file);
long result = checkin(poid, comment, deserializerOid, merge, sync, file.length(), file.getName(), fis);
public long checkin(long poid, String comment, long deserializerOid, boolean merge, boolean sync, Path file) throws IOException, UserException, ServerException {
FileInputStream fis = new FileInputStream(file.toFile());
long result = checkin(poid, comment, deserializerOid, merge, sync, file.toFile().length(), file.getFileName().toString(), fis);
if (sync) {
fis.close();
}
Expand Down Expand Up @@ -287,8 +287,8 @@ public void download(long roid, long serializerOid, OutputStream outputStream) {
}
}

public void download(long roid, long serializerOid, File file) throws IOException {
FileOutputStream outputStream = new FileOutputStream(file);
public void download(long roid, long serializerOid, Path file) throws IOException {
FileOutputStream outputStream = new FileOutputStream(file.toFile());
try {
download(roid, serializerOid, outputStream);
} finally {
Expand Down
23 changes: 3 additions & 20 deletions Shared/src/org/bimserver/plugins/deserializers/Deserializer.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,15 @@
package org.bimserver.plugins.deserializers;

/******************************************************************************
* Copyright (C) 2009-2015 BIMserver.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/

import java.io.File;
import java.io.InputStream;
import java.nio.file.Path;

import org.bimserver.emf.IfcModelInterface;
import org.bimserver.emf.PackageMetaData;

public interface Deserializer {
void init(PackageMetaData packageMetaData);
IfcModelInterface read(File file, ByteProgressReporter progressReporter) throws DeserializeException;
IfcModelInterface read(Path file, ByteProgressReporter progressReporter) throws DeserializeException;
IfcModelInterface read(InputStream inputStream, String fileName, long fileSize, ByteProgressReporter progressReporter) throws DeserializeException;
IfcModelInterface read(File file) throws DeserializeException;
IfcModelInterface read(Path file) throws DeserializeException;
IfcModelInterface read(InputStream inputStream, String fileName, long fileSize) throws DeserializeException;
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,10 @@
package org.bimserver.plugins.deserializers;

/******************************************************************************
* Copyright (C) 2009-2015 BIMserver.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;

import org.bimserver.emf.IfcModelInterface;
import org.bimserver.emf.PackageMetaData;
Expand All @@ -45,12 +28,12 @@ public IfcModelInterface read(InputStream in, String filename, long fileSize) th
}

@Override
public IfcModelInterface read(File file, ByteProgressReporter progressReporter) throws DeserializeException {
public IfcModelInterface read(Path file, ByteProgressReporter progressReporter) throws DeserializeException {
FileInputStream fileInputStream;
try {
fileInputStream = new FileInputStream(file);
fileInputStream = new FileInputStream(file.toFile());
try {
return read(fileInputStream, file.getName(), file.length(), progressReporter);
return read(fileInputStream, file.getFileName().toString(), file.toFile().length(), progressReporter);
} finally {
try {
fileInputStream.close();
Expand All @@ -63,7 +46,7 @@ public IfcModelInterface read(File file, ByteProgressReporter progressReporter)
}
}

public IfcModelInterface read(File file) throws DeserializeException {
public IfcModelInterface read(Path file) throws DeserializeException {
return read(file, null);
}
}
15 changes: 9 additions & 6 deletions Shared/src/org/bimserver/plugins/serializers/EmfSerializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
*****************************************************************************/

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;

import org.bimserver.emf.IdEObject;
import org.bimserver.emf.IdEObjectImpl;
Expand Down Expand Up @@ -127,11 +127,14 @@ public void writeToOutputStream(OutputStream outputStream, ProgressReporter prog
if(progressReporter!=null) progressReporter.update(1, 1);
}

public void writeToFile(File file, ProgressReporter progressReporter) throws SerializerException {
public void writeToFile(Path file, ProgressReporter progressReporter) throws SerializerException {
try {
FileOutputStream fos = new FileOutputStream(file);
writeToOutputStream(fos, progressReporter);
fos.close();
OutputStream outputStream = Files.newOutputStream(file);
try {
writeToOutputStream(outputStream, progressReporter);
} finally {
outputStream.close();
}
} catch (FileNotFoundException e) {
LOGGER.error("", e);
} catch (IOException e) {
Expand Down
21 changes: 2 additions & 19 deletions Shared/src/org/bimserver/plugins/serializers/Serializer.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,9 @@
package org.bimserver.plugins.serializers;

/******************************************************************************
* Copyright (C) 2009-2015 BIMserver.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Path;

import org.bimserver.emf.IfcModelInterface;
import org.bimserver.emf.PackageMetaData;
Expand All @@ -29,7 +12,7 @@

public interface Serializer {
void init(IfcModelInterface model, ProjectInfo projectInfo, PluginManager pluginManager, RenderEnginePlugin renderEnginePlugin, PackageMetaData packageMetaData, boolean normalizeOids) throws SerializerException;
void writeToFile(File file, ProgressReporter progressReporter) throws SerializerException;
void writeToFile(Path file, ProgressReporter progressReporter) throws SerializerException;
byte[] getBytes();
IfcModelInterface getModel();
InputStream getInputStream() throws IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,9 @@
package org.bimserver.plugins.services;

/******************************************************************************
* Copyright (C) 2009-2015 BIMserver.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Path;

import org.bimserver.emf.IfcModelInterface;
import org.bimserver.interfaces.objects.SProject;
Expand All @@ -44,9 +27,9 @@ public interface BimServerClientInterface extends ServiceHolder {
void commit(IfcModelInterface model, String comment);

void download(long roid, long serializerOid, OutputStream outputStream);
void download(long roid, long serializerOid, File file) throws IOException;
void download(long roid, long serializerOid, Path file) throws IOException;

long checkin(long poid, String string, long deserializerOid, boolean merge, boolean sync, File file) throws IOException, UserException, ServerException;
long checkin(long poid, String string, long deserializerOid, boolean merge, boolean sync, Path file) throws IOException, UserException, ServerException;

/**
* Convenience method that given you the InputStream belonging to an already started download
Expand Down
27 changes: 5 additions & 22 deletions Tests/src/org/bimserver/test/AddFurniture.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
package org.bimserver.test;

/******************************************************************************
* Copyright (C) 2009-2015 BIMserver.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/

import java.io.File;
import java.nio.file.Paths;
import java.util.List;

import org.bimserver.LocalDevPluginLoader;
Expand Down Expand Up @@ -54,17 +37,17 @@
public class AddFurniture {
public static void main(String[] args) {
try {
PluginManager pluginManager = LocalDevPluginLoader.createPluginManager(new File("home"));
PluginManager pluginManager = LocalDevPluginLoader.createPluginManager(Paths.get("home"));
DeserializerPlugin deserializerPlugin = pluginManager.getFirstDeserializer("ifc", Schema.IFC2X3TC1, true);

Deserializer deserializer = deserializerPlugin.createDeserializer(null);
deserializer.init(pluginManager.getMetaDataManager().getPackageMetaData("ifc2x3tc1"));

IfcModelInterface model = deserializer.read(new File("../TestData/data/AC9R1-Haus-G-H-Ver2-2x3.ifc"));
IfcModelInterface model = deserializer.read(Paths.get("../TestData/data/AC9R1-Haus-G-H-Ver2-2x3.ifc"));

deserializer = deserializerPlugin.createDeserializer(null);
deserializer.init(pluginManager.getMetaDataManager().getPackageMetaData("ifc2x3tc1"));
IfcModelInterface furnishingModel = deserializer.read(new File("test.ifc"));
IfcModelInterface furnishingModel = deserializer.read(Paths.get ("test.ifc"));

model.fixOids(new IncrementingOidProvider());
long oid = model.getHighestOid();
Expand Down Expand Up @@ -145,7 +128,7 @@ public static void main(String[] args) {
SerializerPlugin serializerPlugin = pluginManager.getSerializerPlugin("org.bimserver.ifc.step.serializer.IfcStepSerializerPlugin", true);
Serializer serializer = serializerPlugin.createSerializer(null);
serializer.init(model, null, pluginManager, null, null, true);
serializer.writeToFile(new File("withfurn.ifc"), null);
serializer.writeToFile(Paths.get("withfurn.ifc"), null);
} catch (PluginException e) {
e.printStackTrace();
} catch (DeserializeException e) {
Expand Down
Loading

0 comments on commit 0dae54a

Please sign in to comment.