use of org.bimserver.plugins.IfcModelSet in project BIMserver by opensourceBIM.
the class BranchToExistingProjectDatabaseAction method execute.
@Override
public ConcreteRevision execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
Revision oldRevision = getDatabaseSession().get(StorePackage.eINSTANCE.getRevision(), roid, OldQuery.getDefault());
Project oldProject = oldRevision.getProject();
User user = getDatabaseSession().get(StorePackage.eINSTANCE.getUser(), authorization.getUoid(), OldQuery.getDefault());
if (!authorization.hasRightsOnProjectOrSuperProjectsOrSubProjects(user, oldProject)) {
throw new UserException("User has insufficient rights to download revisions from this project");
}
IfcModelSet ifcModelSet = new IfcModelSet();
PackageMetaData lastMetaData = null;
for (ConcreteRevision subRevision : oldRevision.getConcreteRevisions()) {
PackageMetaData packageMetaData = bimServer.getMetaDataManager().getPackageMetaData(subRevision.getProject().getSchema());
IfcModel subModel = new BasicIfcModel(packageMetaData, null);
getDatabaseSession().getMap(subModel, new OldQuery(packageMetaData, subRevision.getProject().getId(), subRevision.getId(), -1, Deep.YES));
subModel.getModelMetaData().setDate(subRevision.getDate());
ifcModelSet.add(subModel);
lastMetaData = packageMetaData;
}
IfcModelInterface model = new BasicIfcModel(lastMetaData, null);
try {
model = bimServer.getMergerFactory().createMerger(getDatabaseSession(), authorization.getUoid()).merge(oldRevision.getProject(), ifcModelSet, new ModelHelper(bimServer.getMetaDataManager(), model));
} catch (MergeException e) {
throw new UserException(e);
}
model.resetOids();
CheckinDatabaseAction checkinDatabaseAction = new CheckinDatabaseAction(bimServer, getDatabaseSession(), getAccessMethod(), destPoid, authorization, model, comment, comment, false, -1);
return checkinDatabaseAction.execute();
}
use of org.bimserver.plugins.IfcModelSet in project BIMserver by opensourceBIM.
the class DownloadByNewJsonQueryDatabaseAction method execute.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public IfcModelInterface execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
List<String> projectNames = new ArrayList<>();
setProgress("Querying database...", -1);
for (long roid : roids) {
Revision revision = getDatabaseSession().get(StorePackage.eINSTANCE.getRevision(), roid, OldQuery.getDefault());
projectNames.add(revision.getProject().getName() + "." + revision.getId());
}
String name = Joiner.on("-").join(projectNames);
PackageMetaData lastPackageMetaData = null;
Project lastProject = null;
IfcModelSet ifcModelSet = new IfcModelSet();
Map<Integer, Long> pidRoidMap = new HashMap<>();
for (long roid : roids) {
Revision revision = getDatabaseSession().get(StorePackage.eINSTANCE.getRevision(), roid, OldQuery.getDefault());
lastProject = revision.getProject();
PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(revision.getProject().getSchema());
lastPackageMetaData = packageMetaData;
JsonQueryObjectModelConverter converter = new JsonQueryObjectModelConverter(packageMetaData);
ObjectNode queryObject;
try {
queryObject = OBJECT_MAPPER.readValue(json, ObjectNode.class);
Query query = converter.parseJson("query", (ObjectNode) queryObject);
pidRoidMap.put(revision.getProject().getId(), roid);
IfcModelInterface ifcModel = new ServerIfcModel(packageMetaData, pidRoidMap, getDatabaseSession());
ifcModelSet.add(ifcModel);
QueryObjectProvider queryObjectProvider = new QueryObjectProvider(getDatabaseSession(), getBimServer(), query, Collections.singleton(roid), packageMetaData);
HashMapVirtualObject next = queryObjectProvider.next();
while (next != null) {
IdEObject newObject = packageMetaData.create(next.eClass());
IdEObjectImpl idEObjectImpl = (IdEObjectImpl) newObject;
idEObjectImpl.setPid(revision.getProject().getId());
idEObjectImpl.setOid(next.getOid());
for (EAttribute eAttribute : newObject.eClass().getEAllAttributes()) {
Object value = next.eGet(eAttribute);
if (eAttribute.isMany()) {
List<?> list = (List<?>) value;
if (list != null) {
AbstractEList targetList = (AbstractEList) newObject.eGet(eAttribute);
for (Object item : list) {
targetList.addUnique(item);
}
}
} else {
if (value != null || eAttribute.isUnsettable()) {
newObject.eSet(eAttribute, value);
}
}
}
ifcModel.add(next.getOid(), newObject);
next = queryObjectProvider.next();
}
queryObjectProvider = new QueryObjectProvider(getDatabaseSession(), getBimServer(), query, Collections.singleton(roid), packageMetaData);
next = queryObjectProvider.next();
while (next != null) {
IdEObject idEObject = ifcModel.get(next.getOid());
if (idEObject.eClass() != next.eClass()) {
// Something is wrong
throw new RuntimeException("Classes not the same");
}
for (EReference eReference : idEObject.eClass().getEAllReferences()) {
if (eReference.isMany()) {
List refOids = (List) next.eGet(eReference);
AbstractEList<IdEObject> list = (AbstractEList<IdEObject>) idEObject.eGet(eReference);
if (refOids != null) {
for (Object refOid : refOids) {
if (refOid instanceof Long) {
IdEObject ref = ifcModel.get((long) refOid);
if (ref != null) {
if (eReference.isUnique()) {
list.add(ref);
} else {
list.addUnique(ref);
}
}
} else if (refOid instanceof HashMapWrappedVirtualObject) {
// IdEObject ref = ifcModel.get(((HashMapWrappedVirtualObject) refOid).get);
// if (ref != null) {
// list.add(ref);
// }
} else if (refOid instanceof HashMapVirtualObject) {
HashMapVirtualObject hashMapVirtualObject = (HashMapVirtualObject) refOid;
IdEObject listObject = packageMetaData.create(hashMapVirtualObject.eClass());
List subList = (List<?>) hashMapVirtualObject.get("List");
List newList = (List<?>) listObject.eGet(listObject.eClass().getEStructuralFeature("List"));
for (Object o : subList) {
if (o instanceof HashMapWrappedVirtualObject) {
newList.add(convertWrapped(revision, ifcModel, (HashMapWrappedVirtualObject) o));
} else {
newList.add(o);
}
}
list.addUnique(listObject);
} else {
}
}
}
} else {
Object r = next.eGet(eReference);
if (r instanceof Long) {
long refOid = (Long) r;
idEObject.eSet(eReference, ifcModel.get(refOid));
} else if (r instanceof HashMapWrappedVirtualObject) {
idEObject.eSet(eReference, convertWrapped(revision, ifcModel, (HashMapWrappedVirtualObject) r));
} else if (r instanceof HashMapVirtualObject) {
} else {
}
}
}
next = queryObjectProvider.next();
}
ifcModel.getModelMetaData().setName(name);
ifcModel.getModelMetaData().setRevisionId(1);
if (getAuthorization().getUoid() != -1) {
ifcModel.getModelMetaData().setAuthorizedUser(getUserByUoid(getAuthorization().getUoid()).getName());
}
ifcModel.getModelMetaData().setDate(new Date());
} catch (IOException e1) {
e1.printStackTrace();
} catch (IfcModelInterfaceException e) {
e.printStackTrace();
} catch (QueryException e) {
e.printStackTrace();
}
}
IfcModelInterface ifcModel = new ServerIfcModel(lastPackageMetaData, pidRoidMap, 0, getDatabaseSession());
if (ifcModelSet.size() > 1) {
setProgress("Merging IFC data...", -1);
try {
ifcModel = getBimServer().getMergerFactory().createMerger(getDatabaseSession(), getAuthorization().getUoid()).merge(lastProject, ifcModelSet, new ModelHelper(getBimServer().getMetaDataManager(), ifcModel));
} catch (MergeException e) {
throw new UserException(e);
}
} else {
ifcModel = ifcModelSet.iterator().next();
}
ifcModel.getModelMetaData().setName(name);
// ifcModel.getModelMetaData().setRevisionId(project.getRevisions().indexOf(virtualRevision) + 1);
if (getAuthorization().getUoid() != -1) {
ifcModel.getModelMetaData().setAuthorizedUser(getUserByUoid(getAuthorization().getUoid()).getName());
}
ifcModel.getModelMetaData().setDate(new Date());
return ifcModel;
// for (Long roid : roids) {
// Revision virtualRevision = getRevisionByRoid(roid);
// pidRoidMap.put(virtualRevision.getProject().getId(), virtualRevision.getOid());
// project = virtualRevision.getProject();
// name += project.getName() + "-" + virtualRevision.getId() + "-";
// try {
// getAuthorization().canDownload(roid);
// } catch (UserException e) {
// if (!getAuthorization().hasRightsOnProjectOrSuperProjectsOrSubProjects(user, project)) {
// throw new UserException("User has insufficient rights to download revisions from this project");
// }
// if (!getAuthorization().hasRightsOnProjectOrSuperProjectsOrSubProjects(user, project)) {
// throw new UserException("User has insufficient rights to download revisions from this project");
// }
// }
// int size = 0;
//
// for (ConcreteRevision concreteRevision : virtualRevision.getConcreteRevisions()) {
// try {
// int highestStopId = findHighestStopRid(project, concreteRevision);
//
// PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(concreteRevision.getProject().getSchema());
// lastPackageMetaData = packageMetaData;
// IfcModelInterface subModel = new ServerIfcModel(packageMetaData, pidRoidMap, getDatabaseSession());
//
// OldQuery databaseQuery = new OldQuery(packageMetaData, concreteRevision.getProject().getId(), concreteRevision.getId(), virtualRevision.getOid(), null, Deep.NO, highestStopId);
// databaseQuery.updateOidCounters(concreteRevision, getDatabaseSession());
// JsonObject queryObject = (JsonObject)query;
// JsonArray queries = queryObject.get("queries").getAsJsonArray();
// for (JsonElement queryElement : queries) {
// processQueryPart(packageMetaData, queryObject, (JsonObject) queryElement, subModel, databaseQuery);
// }
//
// size += subModel.size();
// subModel.getModelMetaData().setDate(concreteRevision.getDate());
// subModel.fixInverseMismatches();
// checkGeometry(serializerPluginConfiguration, getBimServer().getPluginManager(), subModel, project, concreteRevision, virtualRevision);
// ifcModelSet.add(subModel);
// } catch (GeometryGeneratingException | IfcModelInterfaceException e) {
// throw new UserException(e);
// }
// }
//
// }
// TODO check, double merging??
// IfcModelInterface ifcModel = new BasicIfcModel(lastPackageMetaData, pidRoidMap);
// if (ifcModelSet.size() > 1) {
// try {
// ifcModel = getBimServer().getMergerFactory().createMerger(getDatabaseSession(), getAuthorization().getUoid()).merge(project, ifcModelSet, new ModelHelper(getBimServer().getMetaDataManager(), ifcModel));
// } catch (MergeException e) {
// throw new UserException(e);
// }
// } else {
// ifcModel = ifcModelSet.iterator().next();
// }
// if (name.endsWith("-")) {
// name = name.substring(0, name.length()-1);
// }
}
use of org.bimserver.plugins.IfcModelSet in project BIMserver by opensourceBIM.
the class DownloadCompareDatabaseAction method execute.
@Override
public IfcModelInterface execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException, ServerException {
try {
Revision revision1 = getRevisionByRoid(roid1);
Revision revision2 = getRevisionByRoid(roid2);
Project project = revision1.getProject();
// bimServer.getCompareCache().getCompareResults(roid1,
CompareResult compareResults = null;
// roid2, compareType,
// compareIdentifier);
IfcModelInterface model1 = new DownloadDatabaseAction(getBimServer(), getDatabaseSession(), getAccessMethod(), roid1, -1, -1, getAuthorization(), null).execute();
IfcModelInterface model2 = new DownloadDatabaseAction(getBimServer(), getDatabaseSession(), getAccessMethod(), roid2, -1, -1, getAuthorization(), null).execute();
try {
compareResults = getModelCompare().compare(model1, model2, compareType);
} catch (ModelCompareException e) {
throw new UserException(e);
}
// bimServer.getCompareCache().storeResults(roid1, roid2,
// compareType, compareIdentifier, compareResults);
ModelMerger merger = getBimServer().getMergerFactory().createMerger(getDatabaseSession(), getAuthorization().getUoid());
PackageMetaData packageMetaData = model1.getPackageMetaData();
IfcModelInterface mergedModel = new ServerIfcModel(packageMetaData, null, getDatabaseSession());
mergedModel = merger.merge(project, new IfcModelSet(model1, model2), new ModelHelper(getBimServer().getMetaDataManager(), mergedModel));
mergedModel.getModelMetaData().setName(project.getName() + "." + revision1.getId() + "." + revision2.getId());
Set<Long> added = new HashSet<Long>();
Set<Long> modified = new HashSet<Long>();
Set<Long> deleted = new HashSet<Long>();
for (CompareContainer compareContainer : compareResults.getItems()) {
for (CompareItem compareItem : compareContainer.getItems()) {
DataObject dataObject = compareItem.getDataObject();
if (compareItem instanceof ObjectAdded) {
added.add(dataObject.getOid());
} else if (compareItem instanceof ObjectModified) {
modified.add(dataObject.getOid());
} else if (compareItem instanceof ObjectRemoved) {
deleted.add(dataObject.getOid());
}
}
}
EClass ifcColourRgbClass = packageMetaData.getEClass("IfcColourRgb");
EStructuralFeature nameFeature = ifcColourRgbClass.getEStructuralFeature("Name");
EStructuralFeature redFeature = ifcColourRgbClass.getEStructuralFeature("Red");
EStructuralFeature greenFeature = ifcColourRgbClass.getEStructuralFeature("Green");
EStructuralFeature blueFeature = ifcColourRgbClass.getEStructuralFeature("Blue");
IdEObject red = mergedModel.createAndAdd(ifcColourRgbClass);
red.eSet(nameFeature, "red");
red.eSet(redFeature, 0.5D);
red.eSet(greenFeature, 0.0D);
red.eSet(blueFeature, 0.0D);
IdEObject green = mergedModel.createAndAdd(ifcColourRgbClass);
green.eSet(nameFeature, "green");
green.eSet(redFeature, 0D);
green.eSet(greenFeature, 0.5D);
green.eSet(blueFeature, 0D);
IdEObject blue = mergedModel.createAndAdd(ifcColourRgbClass);
blue.eSet(nameFeature, "blue");
blue.eSet(redFeature, 0D);
blue.eSet(greenFeature, 0D);
blue.eSet(blueFeature, 0.5D);
for (IdEObject product : mergedModel.getAllWithSubTypes(packageMetaData.getEClass("IfcProduct"))) {
IdEObject color = null;
if (added.contains(product.getOid())) {
color = green;
} else if (deleted.contains(product.getOid())) {
color = red;
} else if (modified.contains(product.getOid())) {
color = blue;
}
if (color != null) {
setColor(mergedModel, product, color);
}
}
mergedModel.fixOidCounter();
return mergedModel;
} catch (IfcModelInterfaceException e) {
throw new UserException(e);
} catch (MergeException e) {
throw new UserException(e);
}
}
use of org.bimserver.plugins.IfcModelSet in project BIMserver by opensourceBIM.
the class DownloadDatabaseAction method execute.
@Override
public IfcModelInterface execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException, ServerException {
Revision revision = getRevisionByRoid(roid);
PluginConfiguration serializerPluginConfiguration = getDatabaseSession().get(StorePackage.eINSTANCE.getPluginConfiguration(), serializerOid, OldQuery.getDefault());
getAuthorization().canDownload(roid);
if (revision == null) {
throw new UserException("Revision with oid " + roid + " not found");
}
Project project = revision.getProject();
User user = getUserByUoid(getAuthorization().getUoid());
try {
getAuthorization().canDownload(roid);
} catch (UserException e) {
if (!getAuthorization().hasRightsOnProjectOrSuperProjectsOrSubProjects(user, project)) {
throw new UserException("User has insufficient rights to download revisions from this project");
}
}
IfcModelSet ifcModelSet = new IfcModelSet();
long incrSize = 0;
EList<ConcreteRevision> concreteRevisions = revision.getConcreteRevisions();
if (concreteRevisions.size() == 0) {
throw new ServerException("No concrete revisions in revision");
}
for (ConcreteRevision subRevision : concreteRevisions) {
incrSize += subRevision.getSize();
}
final long totalSize = incrSize;
final AtomicLong total = new AtomicLong();
IfcHeader ifcHeader = null;
PackageMetaData lastPackageMetaData = null;
Map<Integer, Long> pidRoidMap = new HashMap<>();
pidRoidMap.put(project.getId(), roid);
for (ConcreteRevision concreteRevision : concreteRevisions) {
if (concreteRevision.getUser().getOid() != ignoreUoid) {
PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(concreteRevision.getProject().getSchema());
lastPackageMetaData = packageMetaData;
IfcModel subModel = new ServerIfcModel(packageMetaData, pidRoidMap, getDatabaseSession());
ifcHeader = concreteRevision.getIfcHeader();
int highestStopId = findHighestStopRid(project, concreteRevision);
OldQuery query = new OldQuery(packageMetaData, concreteRevision.getProject().getId(), concreteRevision.getId(), concreteRevision.getOid(), objectIDM, Deep.YES, highestStopId);
subModel.addChangeListener(new IfcModelChangeListener() {
@Override
public void objectAdded(IdEObject idEObject) {
total.incrementAndGet();
if (totalSize == 0) {
setProgress("Preparing download...", 0);
} else {
setProgress("Preparing download...", (int) Math.round(100.0 * total.get() / totalSize));
}
}
});
query.updateOidCounters(concreteRevision, getDatabaseSession());
getDatabaseSession().getMap(subModel, query);
if (serializerPluginConfiguration != null) {
try {
checkGeometry(serializerPluginConfiguration, getBimServer().getPluginManager(), subModel, project, concreteRevision, revision);
} catch (GeometryGeneratingException e) {
throw new UserException(e);
}
}
subModel.getModelMetaData().setDate(concreteRevision.getDate());
ifcModelSet.add(subModel);
}
}
IfcModelInterface ifcModel = new ServerIfcModel(lastPackageMetaData, pidRoidMap, getDatabaseSession());
if (ifcModelSet.size() > 1) {
try {
ifcModel = getBimServer().getMergerFactory().createMerger(getDatabaseSession(), getAuthorization().getUoid()).merge(revision.getProject(), ifcModelSet, new ModelHelper(getBimServer().getMetaDataManager(), ifcModel));
} catch (MergeException e) {
throw new UserException(e);
}
} else {
ifcModel = ifcModelSet.iterator().next();
}
if (ifcHeader != null) {
ifcHeader.load();
ifcModel.getModelMetaData().setIfcHeader(ifcHeader);
}
ifcModel.getModelMetaData().setName(project.getName() + "." + revision.getId());
ifcModel.getModelMetaData().setRevisionId(project.getRevisions().indexOf(revision) + 1);
if (user != null) {
ifcModel.getModelMetaData().setAuthorizedUser(user.getName());
}
ifcModel.getModelMetaData().setDate(revision.getDate());
if (revision.getProject().getGeoTag() != null) {
// ifcModel.setLon(revision.getProject().getGeoTag().getX());
// ifcModel.setLat(revision.getProject().getGeoTag().getY());
// ifcModel.setAltitude((int)
// revision.getProject().getGeoTag().getZ());
// ifcModel.setDirectionAngle(revision.getProject().getGeoTag().getDirectionAngle());
// try {
// CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:" +
// revision.getProject().getGeoTag().getEpsg());
// CoordinateReferenceSystem targetCRS =
// DefaultGeocentricCRS.CARTESIAN;
// MathTransform transform = CRS.findMathTransform(sourceCRS,
// targetCRS, true);
// float[] in = new
// float[]{revision.getProject().getGeoTag().getX1(),
// revision.getProject().getGeoTag().getY1(),
// revision.getProject().getGeoTag().getZ1()};
// float[] result = new float[3];
// transform.transform(in, 0, result, 0, 1);
// IfcModel.setLon(result[0]);
// IfcModel.setLat(result[1]);
// } catch (NoSuchAuthorityCodeException e) {
// LOGGER.error("", e);
// } catch (FactoryException e) {
// LOGGER.error("", e);
// } catch (MismatchedDimensionException e) {
// LOGGER.error("", e);
// } catch (TransformException e) {
// LOGGER.error("", e);
// }
}
return ifcModel;
}
use of org.bimserver.plugins.IfcModelSet in project BIMserver by opensourceBIM.
the class DownloadProjectsDatabaseAction method execute.
@Override
public IfcModelInterface execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
User user = getUserByUoid(getAuthorization().getUoid());
Project project = null;
String projectName = "";
IfcModelSet ifcModelSet = new IfcModelSet();
long incrSize = 0;
for (long roid : roids) {
Revision revision = getRevisionByRoid(roid);
for (ConcreteRevision subRevision : revision.getConcreteRevisions()) {
incrSize += subRevision.getSize();
}
}
final long totalSize = incrSize;
final AtomicLong total = new AtomicLong();
PluginConfiguration serializerPluginConfiguration = getDatabaseSession().get(StorePackage.eINSTANCE.getPluginConfiguration(), serializerOid, OldQuery.getDefault());
PackageMetaData lastPackageMetaData = null;
IfcHeader ifcHeader = null;
Map<Integer, Long> pidRoidMap = new HashMap<>();
for (long roid : roids) {
Revision revision = getRevisionByRoid(roid);
project = revision.getProject();
pidRoidMap.put(project.getId(), roid);
if (getAuthorization().hasRightsOnProjectOrSuperProjectsOrSubProjects(user, project)) {
for (ConcreteRevision concreteRevision : revision.getConcreteRevisions()) {
ifcHeader = concreteRevision.getIfcHeader();
PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(concreteRevision.getProject().getSchema());
lastPackageMetaData = packageMetaData;
IfcModel subModel = new ServerIfcModel(packageMetaData, pidRoidMap, getDatabaseSession());
int highestStopId = findHighestStopRid(project, concreteRevision);
OldQuery query = new OldQuery(packageMetaData, concreteRevision.getProject().getId(), concreteRevision.getId(), revision.getOid(), objectIDM, Deep.YES, highestStopId);
subModel.addChangeListener(new IfcModelChangeListener() {
@Override
public void objectAdded(IdEObject idEObject) {
total.incrementAndGet();
if (totalSize == 0) {
setProgress("Preparing download...", 0);
} else {
setProgress("Preparing download...", (int) Math.round(100.0 * total.get() / totalSize));
}
}
});
query.updateOidCounters(concreteRevision, getDatabaseSession());
getDatabaseSession().getMap(subModel, query);
projectName += concreteRevision.getProject().getName() + "-";
subModel.getModelMetaData().setDate(concreteRevision.getDate());
try {
checkGeometry(serializerPluginConfiguration, getBimServer().getPluginManager(), subModel, project, concreteRevision, revision);
} catch (GeometryGeneratingException e) {
throw new UserException(e);
}
ifcModelSet.add(subModel);
}
} else {
throw new UserException("User has no rights on project " + project.getOid());
}
}
IfcModelInterface ifcModel = new ServerIfcModel(lastPackageMetaData, pidRoidMap, getDatabaseSession());
if (ifcModelSet.size() == 1) {
ifcModel = ifcModelSet.iterator().next();
} else {
try {
ifcModel = getBimServer().getMergerFactory().createMerger(getDatabaseSession(), getAuthorization().getUoid()).merge(project, ifcModelSet, new ModelHelper(getBimServer().getMetaDataManager(), ifcModel));
} catch (MergeException e) {
throw new UserException(e);
}
}
if (ifcHeader != null) {
ifcHeader.load();
ifcModel.getModelMetaData().setIfcHeader(ifcHeader);
}
if (projectName.endsWith("-")) {
projectName = projectName.substring(0, projectName.length() - 1);
}
ifcModel.getModelMetaData().setName(projectName);
return ifcModel;
}
Aggregations