use of org.bimserver.shared.exceptions.ServiceException in project BIMserver by opensourceBIM.
the class CheckinDatabaseAction method execute.
@Override
public ConcreteRevision execute() throws UserException, BimserverDatabaseException {
try {
if (fileSize == -1) {
setProgress("Deserializing IFC file...", -1);
} else {
setProgress("Deserializing IFC file...", 0);
}
if (getModel().size() == 0) {
throw new DeserializeException(DeserializerErrorCode.EMPTY_MODEL_CANNOT_BE_CHECKED_IN, "Cannot checkin empty model");
}
authorization.canCheckin(poid);
project = getProjectByPoid(poid);
int nrConcreteRevisionsBefore = project.getConcreteRevisions().size();
User user = getUserByUoid(authorization.getUoid());
if (project == null) {
throw new UserException("Project with poid " + poid + " not found");
}
if (!authorization.hasRightsOnProjectOrSuperProjects(user, project)) {
throw new UserException("User has no rights to checkin models to this project");
}
if (!MailSystem.isValidEmailAddress(user.getUsername())) {
throw new UserException("Users must have a valid e-mail address to checkin");
}
if (getModel() != null) {
checkCheckSum(project, getModel());
}
long size = 0;
if (getModel() != null) {
for (IdEObject idEObject : getModel().getValues()) {
if (idEObject.eClass().getEAnnotation("hidden") == null) {
size++;
}
}
getModel().fixInverseMismatches();
}
for (ModelCheckerInstance modelCheckerInstance : project.getModelCheckers()) {
if (modelCheckerInstance.isValid()) {
ModelCheckerPlugin modelCheckerPlugin = getBimServer().getPluginManager().getModelCheckerPlugin(modelCheckerInstance.getModelCheckerPluginClassName(), true);
if (modelCheckerPlugin != null) {
ModelChecker modelChecker = modelCheckerPlugin.createModelChecker(null);
ModelCheckerResult result = modelChecker.check(getModel(), modelCheckerInstance.getCompiled());
if (!result.isValid()) {
throw new UserException("Model is not valid according to " + modelCheckerInstance.getName());
}
}
}
}
CreateRevisionResult result = createNewConcreteRevision(getDatabaseSession(), size, project, user, comment.trim());
concreteRevision = result.getConcreteRevision();
IfcHeader ifcHeader = getModel().getModelMetaData().getIfcHeader();
if (ifcHeader != null) {
getDatabaseSession().store(ifcHeader);
concreteRevision.setIfcHeader(ifcHeader);
}
project.getConcreteRevisions().add(concreteRevision);
if (getModel() != null) {
concreteRevision.setChecksum(getModel().getModelMetaData().getChecksum());
}
final NewRevisionAdded newRevisionAdded = getDatabaseSession().create(NewRevisionAdded.class);
newRevisionAdded.setDate(new Date());
newRevisionAdded.setExecutor(user);
final Revision revision = concreteRevision.getRevisions().get(0);
if (newServiceId != -1) {
NewService newService = getDatabaseSession().get(newServiceId, OldQuery.getDefault());
revision.getServicesLinked().add(newService);
}
concreteRevision.setSummary(new SummaryMap(getModel()).toRevisionSummary(getDatabaseSession()));
// If this revision is being created by an external service, store a link to the service in the revision
if (authorization instanceof ExplicitRightsAuthorization) {
ExplicitRightsAuthorization explicitRightsAuthorization = (ExplicitRightsAuthorization) authorization;
if (explicitRightsAuthorization.getSoid() != -1) {
Service service = getDatabaseSession().get(explicitRightsAuthorization.getSoid(), OldQuery.getDefault());
revision.setService(service);
}
}
newRevisionAdded.setRevision(revision);
newRevisionAdded.setProject(project);
newRevisionAdded.setAccessMethod(getAccessMethod());
Revision lastRevision = project.getLastRevision();
IfcModelInterface ifcModel = null;
if (merge && lastRevision != null) {
ifcModel = checkinMerge(lastRevision);
} else {
ifcModel = getModel();
}
ifcModel.fixOidsFlat(getDatabaseSession());
if (getBimServer().getServerSettingsCache().getServerSettings().isGenerateGeometryOnCheckin()) {
setProgress("Generating Geometry...", -1);
UserSettings userSettings = user.getUserSettings();
RenderEnginePluginConfiguration defaultRenderEngine = userSettings.getDefaultRenderEngine();
if (defaultRenderEngine == null) {
throw new UserException("No default render engine has been selected for this user");
}
RenderEnginePool pool = getBimServer().getRenderEnginePools().getRenderEnginePool(model.getPackageMetaData().getSchema(), defaultRenderEngine.getPluginDescriptor().getPluginClassName(), getBimServer().getPluginSettingsCache().getPluginSettings(defaultRenderEngine.getOid()));
GenerateGeometryResult generateGeometry = new GeometryGenerator(getBimServer()).generateGeometry(pool, getBimServer().getPluginManager(), getDatabaseSession(), ifcModel, project.getId(), concreteRevision.getId(), true, geometryCache);
// TODO OUTDATED!!!
// TODO deduplicate (this is duplicated 4 times now!)
concreteRevision.setMultiplierToMm(generateGeometry.getMultiplierToMm());
concreteRevision.setBounds(generateGeometry.getBounds());
concreteRevision.setBoundsUntransformed(generateGeometry.getBoundsUntransformed());
DensityCollection densityCollection = getDatabaseSession().create(DensityCollection.class);
concreteRevision.eSet(StorePackage.eINSTANCE.getConcreteRevision_DensityCollection(), densityCollection);
Collections.sort(generateGeometry.getDensities(), new Comparator<Density>() {
@Override
public int compare(Density o1, Density o2) {
return (int) ((o1.getDensityValue() - o2.getDensityValue()) * 10000000);
}
});
for (Density density : generateGeometry.getDensities()) {
org.bimserver.models.store.Density dbDensity = getDatabaseSession().create(org.bimserver.models.store.Density.class);
dbDensity.setDensity(density.getDensityValue());
dbDensity.setGeometryInfoId(density.getGeometryInfoId());
dbDensity.setTrianglesBelow(density.getNrPrimitives());
dbDensity.setVolume(density.getVolume());
densityCollection.getDensities().add(dbDensity);
}
for (Revision other : concreteRevision.getRevisions()) {
other.setHasGeometry(true);
}
}
if (nrConcreteRevisionsBefore != 0 && !merge) {
// There already was a revision, lets delete it (only when not merging)
concreteRevision.setClear(true);
}
Set<EClass> eClasses = ifcModel.getUsedClasses();
Map<String, Long> startOids = getDatabaseSession().getStartOids();
if (startOids == null) {
throw new BimserverDatabaseException("No objects changed");
}
OidCounters oidCounters = new OidCounters();
for (EClass eClass : eClasses) {
long oid = startOids.get(eClass);
if (!DatabaseSession.perRecordVersioning(eClass)) {
oidCounters.put(eClass, oid);
}
}
concreteRevision.setOidCounters(oidCounters.getBytes());
if (ifcModel != null) {
getDatabaseSession().store(ifcModel.getValues(), project.getId(), concreteRevision.getId());
}
getDatabaseSession().addPostCommitAction(new PostCommitAction() {
@Override
public void execute() throws UserException {
try {
clearCheckinInProgress();
} catch (BimserverDatabaseException | ServiceException e) {
LOGGER.error("", e);
}
getBimServer().getNotificationsManager().notify(new NewRevisionNotification(getBimServer(), project.getOid(), revision.getOid(), authorization));
}
});
getDatabaseSession().store(concreteRevision);
getDatabaseSession().store(project);
} catch (Throwable e) {
try {
clearCheckinInProgress();
} catch (ServiceException e1) {
LOGGER.error("", e1);
}
if (e instanceof BimserverDatabaseException) {
throw (BimserverDatabaseException) e;
}
if (e instanceof UserException) {
throw (UserException) e;
}
LOGGER.error("", e);
throw new UserException(e);
}
return concreteRevision;
}
use of org.bimserver.shared.exceptions.ServiceException in project BIMserver by opensourceBIM.
the class AsyncTestAddExtendedData2 method start.
private void start() {
try {
BimServerClientInterface client = LocalDevSetup.setupJson("http://localhost:8080");
SFile file = new SFile();
file.setData("test".getBytes(Charsets.UTF_8));
file.setMime("text");
file.setFilename("test.txt");
long fileId = client.getServiceInterface().uploadFile(file);
SProject project = client.getServiceInterface().addProject(RandomUtils.nextInt(1, 100000000) + "", "ifc2x3tc1");
SDeserializerPluginConfiguration deserializerForExtension = client.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
long topicId = client.getServiceInterface().initiateCheckin(project.getOid(), deserializerForExtension.getOid());
client.checkinAsync(project.getOid(), "initial", deserializerForExtension.getOid(), false, Paths.get("C:\\Git\\TestFiles\\TestData\\data\\AC11-FZK-Haus-IFC.ifc"), topicId);
while (true) {
SLongCheckinActionState progress = (SLongCheckinActionState) client.getNotificationRegistryInterface().getProgress(topicId);
System.out.println(progress.getState());
if (progress.getState() == SActionState.FINISHED) {
SExtendedDataSchema extendedDataSchemaByNamespace = client.getServiceInterface().getExtendedDataSchemaByName("GEOMETRY_GENERATION_REPORT_JSON_1_1");
SExtendedData extendedData = new SExtendedData();
extendedData.setFileId(fileId);
extendedData.setTitle("test3");
extendedData.setSchemaId(extendedDataSchemaByNamespace.getOid());
client.getServiceInterface().addExtendedDataToRevision(progress.getRoid(), extendedData);
break;
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
} catch (ServiceException e) {
e.printStackTrace();
} catch (PublicInterfaceNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.bimserver.shared.exceptions.ServiceException in project BIMserver by opensourceBIM.
the class TestDatabase method checkLists3.
private void checkLists3() {
DatabaseSession session = database.createSession(OperationType.READ_WRITE);
long xid = -1;
try {
User user = session.create(User.class);
UserSettings userSettings = session.create(UserSettings.class);
SerializerPluginConfiguration serializerPluginConfiguration1 = session.create(SerializerPluginConfiguration.class);
SerializerPluginConfiguration serializerPluginConfiguration2 = session.create(SerializerPluginConfiguration.class);
xid = serializerPluginConfiguration2.getOid();
user.setUserSettings(userSettings);
serializerPluginConfiguration1.setUserSettings(userSettings);
serializerPluginConfiguration2.setUserSettings(userSettings);
session.commit();
} catch (BimserverDatabaseException e) {
e.printStackTrace();
} catch (ServiceException e) {
e.printStackTrace();
} finally {
session.close();
session = database.createSession(OperationType.READ_WRITE);
try {
SerializerPluginConfiguration p1 = session.get(xid, OldQuery.getDefault());
UserSettings userSettings = p1.getUserSettings();
for (SerializerPluginConfiguration p2 : userSettings.getSerializers()) {
System.out.println(p2.getOid() + " - " + p2);
}
} catch (BimserverDatabaseException e) {
e.printStackTrace();
} finally {
session.close();
}
}
}
use of org.bimserver.shared.exceptions.ServiceException in project BIMserver by opensourceBIM.
the class TestDatabase method checkWithAllOfType.
private void checkWithAllOfType() {
DatabaseSession session = database.createSession(OperationType.READ_WRITE);
try {
List<User> users = session.getAllOfType(StorePackage.eINSTANCE.getUser(), User.class, OldQuery.getDefault());
for (User user : users) {
if (user.getName().equals("testuser")) {
System.out.println(user.getName() + ": " + user.getHasRightsOn());
}
}
List<Project> projects = session.getAllOfType(StorePackage.eINSTANCE.getProject(), Project.class, OldQuery.getDefault());
for (Project project : projects) {
if (project.getName().equals("testproject")) {
System.out.println(project.getName() + ": " + project.getHasAuthorizedUsers());
}
}
session.commit();
} catch (BimserverDatabaseException e) {
e.printStackTrace();
} catch (ServiceException e) {
e.printStackTrace();
} finally {
session.close();
}
}
use of org.bimserver.shared.exceptions.ServiceException in project BIMserver by opensourceBIM.
the class TestDatabase method removeWithOid.
private void removeWithOid() {
DatabaseSession session = database.createSession(OperationType.READ_WRITE);
try {
Project p = session.get(StorePackage.eINSTANCE.getProject(), poid, OldQuery.getDefault());
User u = session.get(StorePackage.eINSTANCE.getUser(), uoid, OldQuery.getDefault());
if (!u.getHasRightsOn().remove(p)) {
System.err.println("Not removed");
}
session.store(u);
session.store(p);
session.commit();
} catch (BimserverDatabaseException e) {
e.printStackTrace();
} catch (ServiceException e) {
e.printStackTrace();
} finally {
session.close();
}
}
Aggregations