use of org.bimserver.shared.exceptions.ServiceException in project BIMserver by opensourceBIM.
the class ClientIfcModel method set.
@Override
public void set(IdEObject idEObject, EStructuralFeature eFeature, Object newValue) {
if (!recordChanges) {
return;
}
if (!eFeature.isMany()) {
if (getModelState() != ModelState.LOADING && ((IdEObjectImpl) idEObject).getLoadingState() != State.LOADING) {
try {
if (newValue != EStructuralFeature.Internal.DynamicValueHolder.NIL) {
LowLevelInterface lowLevelInterface = getBimServerClient().getLowLevelInterface();
if (eFeature.getName().equals("wrappedValue")) {
// Wrapped objects get the same oid as their
// "parent" object, so we know which object the
// client wants to update. That's why we can use
// idEObject.getOid() here
// We are making this crazy hack ever crazier, let's
// iterate over our parents features, and see if
// there is one matching our wrapped type...
// Seriously, when there are multiple fields of the
// same type, this fails miserably, a real fix
// should probably store the parent-oid + feature
// name in the wrapped object (requires two extra,
// volatile, fields),
// or we just don't support this (just create a new
// wrapped object too), we could even throw some
// sort of exception. Hack morally okay because it's
// client-side...
EReference foundReference = null;
if (contains(idEObject.getOid())) {
IdEObject parentObject = get(idEObject.getOid());
int found = 0;
foundReference = null;
for (EReference testReference : parentObject.eClass().getEAllReferences()) {
if (((EClass) testReference.getEType()).isSuperTypeOf(idEObject.eClass())) {
foundReference = testReference;
found++;
if (found > 1) {
throw new RuntimeException("Sorry, crazy hack could not resolve the right field, please let BIMserver developer know (debug info: " + parentObject.eClass().getName() + ", " + idEObject.eClass().getName() + ")");
}
}
}
if (eFeature.getEType() == EcorePackage.eINSTANCE.getEString()) {
lowLevelInterface.setWrappedStringAttribute(getTransactionId(), idEObject.getOid(), foundReference.getName(), idEObject.eClass().getName(), (String) newValue);
} else if (eFeature.getEType() == EcorePackage.eINSTANCE.getELong() || eFeature.getEType() == EcorePackage.eINSTANCE.getELongObject()) {
lowLevelInterface.setWrappedLongAttribute(getTransactionId(), idEObject.getOid(), foundReference.getName(), idEObject.eClass().getName(), (Long) newValue);
} else if (eFeature.getEType() == EcorePackage.eINSTANCE.getEDouble() || eFeature.getEType() == EcorePackage.eINSTANCE.getEDoubleObject()) {
lowLevelInterface.setWrappedDoubleAttribute(getTransactionId(), idEObject.getOid(), foundReference.getName(), idEObject.eClass().getName(), (Double) newValue);
} else if (eFeature.getEType() == EcorePackage.eINSTANCE.getEBoolean() || eFeature.getEType() == EcorePackage.eINSTANCE.getEBooleanObject()) {
lowLevelInterface.setWrappedBooleanAttribute(getTransactionId(), idEObject.getOid(), foundReference.getName(), idEObject.eClass().getName(), (Boolean) newValue);
} else if (eFeature.getEType() == EcorePackage.eINSTANCE.getEInt() || eFeature.getEType() == EcorePackage.eINSTANCE.getEIntegerObject()) {
lowLevelInterface.setWrappedIntegerAttribute(getTransactionId(), idEObject.getOid(), foundReference.getName(), idEObject.eClass().getName(), (Integer) newValue);
} else if (eFeature.getEType() == EcorePackage.eINSTANCE.getEByteArray()) {
throw new RuntimeException("Unimplemented " + eFeature.getEType().getName() + " " + newValue);
}
} else {
if (eFeature.getEType() == EcorePackage.eINSTANCE.getEString()) {
lowLevelInterface.setStringAttribute(getTransactionId(), idEObject.getOid(), eFeature.getName(), (String) newValue);
} else if (eFeature.getEType() == EcorePackage.eINSTANCE.getELong() || eFeature.getEType() == EcorePackage.eINSTANCE.getELongObject()) {
lowLevelInterface.setLongAttribute(getTransactionId(), idEObject.getOid(), eFeature.getName(), (Long) newValue);
} else if (eFeature.getEType() == EcorePackage.eINSTANCE.getEDouble() || eFeature.getEType() == EcorePackage.eINSTANCE.getEDoubleObject()) {
lowLevelInterface.setDoubleAttribute(getTransactionId(), idEObject.getOid(), eFeature.getName(), (Double) newValue);
} else if (eFeature.getEType() == EcorePackage.eINSTANCE.getEBoolean() || eFeature.getEType() == EcorePackage.eINSTANCE.getEBooleanObject()) {
lowLevelInterface.setBooleanAttribute(getTransactionId(), idEObject.getOid(), eFeature.getName(), (Boolean) newValue);
} else if (eFeature.getEType() == EcorePackage.eINSTANCE.getEInt() || eFeature.getEType() == EcorePackage.eINSTANCE.getEIntegerObject()) {
lowLevelInterface.setIntegerAttribute(getTransactionId(), idEObject.getOid(), eFeature.getName(), (Integer) newValue);
} else if (eFeature.getEType() == EcorePackage.eINSTANCE.getEByteArray()) {
lowLevelInterface.setByteArrayAttribute(getTransactionId(), idEObject.getOid(), eFeature.getName(), (Byte[]) newValue);
} else if (eFeature.getEType() instanceof EEnum) {
lowLevelInterface.setEnumAttribute(getTransactionId(), idEObject.getOid(), eFeature.getName(), ((Enum<?>) newValue).toString());
} else if (eFeature instanceof EReference) {
if (newValue == null) {
lowLevelInterface.setReference(getTransactionId(), idEObject.getOid(), eFeature.getName(), -1L);
} else {
lowLevelInterface.setReference(getTransactionId(), idEObject.getOid(), eFeature.getName(), ((IdEObject) newValue).getOid());
}
} else {
throw new RuntimeException("Unimplemented " + eFeature.getEType().getName() + " " + newValue);
}
}
} else {
if (eFeature.getEType() == EcorePackage.eINSTANCE.getEString()) {
lowLevelInterface.setStringAttribute(getTransactionId(), idEObject.getOid(), eFeature.getName(), (String) newValue);
} else if (eFeature.getEType() == EcorePackage.eINSTANCE.getELong() || eFeature.getEType() == EcorePackage.eINSTANCE.getELongObject()) {
lowLevelInterface.setLongAttribute(getTransactionId(), idEObject.getOid(), eFeature.getName(), (Long) newValue);
} else if (eFeature.getEType() == EcorePackage.eINSTANCE.getEDouble() || eFeature.getEType() == EcorePackage.eINSTANCE.getEDoubleObject()) {
lowLevelInterface.setDoubleAttribute(getTransactionId(), idEObject.getOid(), eFeature.getName(), (Double) newValue);
} else if (eFeature.getEType() == EcorePackage.eINSTANCE.getEBoolean() || eFeature.getEType() == EcorePackage.eINSTANCE.getEBooleanObject()) {
lowLevelInterface.setBooleanAttribute(getTransactionId(), idEObject.getOid(), eFeature.getName(), (Boolean) newValue);
} else if (eFeature.getEType() == EcorePackage.eINSTANCE.getEInt() || eFeature.getEType() == EcorePackage.eINSTANCE.getEIntegerObject()) {
lowLevelInterface.setIntegerAttribute(getTransactionId(), idEObject.getOid(), eFeature.getName(), (Integer) newValue);
} else if (eFeature.getEType() == EcorePackage.eINSTANCE.getEByteArray()) {
if (newValue instanceof byte[]) {
Byte[] n = new Byte[((byte[]) newValue).length];
for (int i = 0; i < n.length; i++) {
n[i] = ((byte[]) newValue)[i];
}
newValue = n;
}
lowLevelInterface.setByteArrayAttribute(getTransactionId(), idEObject.getOid(), eFeature.getName(), (Byte[]) newValue);
} else if (eFeature.getEType() instanceof EEnum) {
lowLevelInterface.setEnumAttribute(getTransactionId(), idEObject.getOid(), eFeature.getName(), ((Enum<?>) newValue).toString());
} else if (eFeature instanceof EReference) {
if (newValue == null) {
lowLevelInterface.setReference(getTransactionId(), idEObject.getOid(), eFeature.getName(), -1L);
} else {
lowLevelInterface.setReference(getTransactionId(), idEObject.getOid(), eFeature.getName(), ((IdEObject) newValue).getOid());
}
} else {
throw new RuntimeException("Unimplemented " + eFeature.getEType().getName() + " " + newValue);
}
}
}
} catch (ServiceException e) {
LOGGER.error("", e);
} catch (PublicInterfaceNotFoundException e) {
LOGGER.error("", e);
}
}
}
}
use of org.bimserver.shared.exceptions.ServiceException in project BIMserver by opensourceBIM.
the class NotificationsManager method handleIncoming.
public void handleIncoming(ObjectNode request) throws UserException, ConvertException, IOException {
// TODO copied code from JsonHandler
String interfaceName = request.get("interface").asText();
String methodName = request.get("method").asText();
SService sService = servicesMap.getByName(interfaceName);
if (sService == null) {
sService = servicesMap.getBySimpleName(interfaceName);
}
if (sService == null) {
throw new UserException("No service found with name " + interfaceName);
}
SMethod method = sService.getSMethod(methodName);
if (method == null) {
SMethod alternative = servicesMap.findMethod(methodName);
if (alternative == null) {
throw new UserException("Method " + methodName + " not found on " + interfaceName);
} else {
throw new UserException("Method " + methodName + " not found on " + interfaceName + " (suggestion: " + alternative.getService().getSimpleName() + ")");
}
}
KeyValuePair[] parameters = new KeyValuePair[method.getParameters().size()];
if (request.has("parameters")) {
ObjectNode parametersJson = (ObjectNode) request.get("parameters");
for (int i = 0; i < method.getParameters().size(); i++) {
SParameter parameter = method.getParameter(i);
if (parametersJson.has(parameter.getName())) {
parameters[i] = new KeyValuePair(parameter.getName(), converter.fromJson(parameter.getType(), parameter.getGenericType(), parametersJson.get(parameter.getName())));
} else {
LOGGER.error("Missing parameters: " + method.getName() + " -> " + parameter.getName());
}
}
} else {
throw new UserException("Missing 'parameters' field");
}
try {
method.invoke(sService.getInterfaceClass(), service, parameters);
} catch (ServiceException e) {
LOGGER.error("", e);
} catch (ReflectorException e) {
LOGGER.error("", e);
}
}
use of org.bimserver.shared.exceptions.ServiceException in project BIMserver by opensourceBIM.
the class LongStreamingCheckinAction method execute.
public void execute() {
DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.POSSIBLY_WRITE);
try {
checkinDatabaseAction.setDatabaseSession(session);
session.executeAndCommitAction(checkinDatabaseAction, new ProgressHandler() {
private int count;
@Override
public void progress(int current, int max) {
if (count == 0) {
updateProgress("Saving to database (" + fileName + ")", current * 100 / max);
} else {
updateProgress("Saving to database (" + fileName + ", " + count + " try)", current * 100 / max);
}
}
@Override
public void retry(int count) {
this.count = count;
}
}, new RollbackListener() {
@Override
public void rollback() {
try {
checkinDatabaseAction.rollback();
} catch (BimserverDatabaseException e) {
LOGGER.error("", e);
}
}
});
this.roid = checkinDatabaseAction.getRevision().getOid();
} catch (Exception e) {
try (DatabaseSession tmpSession = getBimServer().getDatabase().createSession(OperationType.READ_WRITE)) {
Project project = tmpSession.get(checkinDatabaseAction.getPoid(), OldQuery.getDefault());
project.setCheckinInProgress(0);
tmpSession.store(project);
try {
tmpSession.commit();
} catch (ServiceException e2) {
LOGGER.error("", e2);
}
} catch (BimserverDatabaseException e1) {
LOGGER.error("", e1);
}
if (e instanceof UserException) {
if (e.getCause() instanceof DeserializeException) {
this.deserializerException = (DeserializeException) e.getCause();
}
} else if (e instanceof BimserverConcurrentModificationDatabaseException) {
// Ignore
} else {
LOGGER.error("", e);
}
error(e);
} finally {
try {
checkinDatabaseAction.close();
} catch (IOException e) {
LOGGER.error("", e);
}
session.close();
if (getActionState() != ActionState.AS_ERROR) {
changeActionState(ActionState.FINISHED, "Checkin of " + fileName, 100);
}
done();
}
}
use of org.bimserver.shared.exceptions.ServiceException in project BIMserver by opensourceBIM.
the class StreamingCheckinDatabaseAction method execute.
@Override
public ConcreteRevision execute() throws UserException, BimserverDatabaseException {
try {
if (inputStream instanceof RestartableInputStream) {
((RestartableInputStream) inputStream).restartIfAtEnd();
}
getDatabaseSession().clearPostCommitActions();
if (fileSize == -1) {
// setProgress("Deserializing IFC file...", -1);
} else {
setProgress("Deserializing IFC file...", 0);
}
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);
// }
packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(project.getSchema());
// TODO checksum
// TODO modelcheckers
// TODO test ifc4
// 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 = bimServer.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(), -1, project, user, comment.trim());
newRevision = result.getRevisions().get(0);
long newRoid = newRevision.getOid();
// TODO check
QueryContext queryContext = new QueryContext(getDatabaseSession(), packageMetaData, result.getConcreteRevision().getProject().getId(), result.getConcreteRevision().getId(), newRoid, result.getConcreteRevision().getOid(), -1);
AtomicLong bytesRead = new AtomicLong();
deserializer.setProgressReporter(new ByteProgressReporter() {
@Override
public void progress(long byteNumber) {
bytesRead.set(byteNumber);
if (fileSize != -1) {
int perc = (int) (100.0 * byteNumber / fileSize);
setProgress("Deserializing...", perc);
}
}
});
// This will read the full stream of objects and write to the database directly
long size = deserializer.read(inputStream, fileName, fileSize, queryContext);
Set<EClass> eClasses = deserializer.getSummaryMap().keySet();
Map<String, Long> startOids = getDatabaseSession().getStartOids();
if (startOids == null) {
throw new BimserverDatabaseException("No objects changed");
}
OidCounters oidCounters = new OidCounters();
for (EClass eClass : eClasses) {
if (!DatabaseSession.perRecordVersioning(eClass)) {
oidCounters.put(eClass, startOids.get(fullname(eClass)));
}
}
queryContext.setOidCounters(oidCounters);
concreteRevision = result.getConcreteRevision();
concreteRevision.setOidCounters(oidCounters.getBytes());
setProgress("Generating inverses/opposites...", -1);
fixInverses(packageMetaData, newRoid, deserializer.getSummaryMap());
ProgressListener progressListener = new ProgressListener() {
@Override
public void updateProgress(String state, int percentage) {
setProgress("Generating geometry...", percentage);
}
};
GeometryGenerationReport report = null;
if (getBimServer().getServerSettingsCache().getServerSettings().isGenerateGeometryOnCheckin()) {
report = new GeometryGenerationReport();
report.setOriginalIfcFileName(fileName);
report.setOriginalIfcFileSize(bytesRead.get());
report.setNumberOfObjects(size);
report.setOriginalDeserializer(pluginBundleVersion.getGroupId() + "." + pluginBundleVersion.getArtifactId() + ":" + pluginBundleVersion.getVersion());
StreamingGeometryGenerator geometryGenerator = new StreamingGeometryGenerator(getBimServer(), progressListener, -1L, report);
setProgress("Generating geometry...", 0);
GenerateGeometryResult generateGeometry = geometryGenerator.generateGeometry(getActingUid(), getDatabaseSession(), queryContext, size);
for (Revision other : concreteRevision.getRevisions()) {
other.setHasGeometry(true);
}
concreteRevision.setMultiplierToMm(generateGeometry.getMultiplierToMm());
concreteRevision.setBounds(generateGeometry.getBounds());
concreteRevision.setBoundsUntransformed(generateGeometry.getBoundsUntransformed());
// TODO terrible code, but had to get it going quickly, will cleanup later
generateDensityAndBounds(result, generateGeometry, concreteRevision);
}
final GeometryGenerationReport finalReport = report;
// float[] quantizationMatrix = createQuantizationMatrixFromBounds(newRevision.getBoundsMm());
// generateQuantizedVertices(getDatabaseSession(), newRevision, quantizationMatrix, generateGeometry.getMultiplierToMm());
setProgress("Doing other stuff...", -1);
eClasses = deserializer.getSummaryMap().keySet();
oidCounters = new OidCounters();
for (EClass eClass : eClasses) {
String fullname = fullname(eClass);
Long oid = startOids.get(fullname);
if (oid == null) {
// This happens almost never, but it most certainly must be a bug, adding verbose logging to try and identify the problem
LOGGER.info("");
LOGGER.info("EClass " + eClass.getName() + " not found in startOids, please report");
LOGGER.info("eClasses:");
for (EClass eClass2 : eClasses) {
LOGGER.info(fullname(eClass2));
}
LOGGER.info("");
LOGGER.info("startOids");
for (String fullname2 : startOids.keySet()) {
LOGGER.info(fullname2 + ": " + startOids.get(fullname2));
}
throw new UserException("EClass " + eClass.getName() + " not found in startOids, please report");
}
if (!DatabaseSession.perRecordVersioning(eClass)) {
oidCounters.put(eClass, oid);
}
}
if (startOids.containsKey(fullname(GeometryPackage.eINSTANCE.getGeometryInfo())) && startOids.containsKey(fullname(GeometryPackage.eINSTANCE.getGeometryData()))) {
oidCounters.put(GeometryPackage.eINSTANCE.getGeometryInfo(), startOids.get(fullname(GeometryPackage.eINSTANCE.getGeometryInfo())));
oidCounters.put(GeometryPackage.eINSTANCE.getGeometryData(), startOids.get(fullname(GeometryPackage.eINSTANCE.getGeometryData())));
oidCounters.put(GeometryPackage.eINSTANCE.getBuffer(), startOids.get(fullname(GeometryPackage.eINSTANCE.getBuffer())));
}
concreteRevision = result.getConcreteRevision();
concreteRevision.setOidCounters(oidCounters.getBytes());
// Clear the cache, we don't want it to cache incomplete oidcounters
ConcreteRevisionStackFrame.clearCache(concreteRevision.getOid());
result.getConcreteRevision().setSize(size);
for (Revision revision : result.getRevisions()) {
revision.setSize(((revision.getSize() == null || revision.getSize() == -1) ? 0 : revision.getSize()) + concreteRevision.getSize());
}
IfcHeader ifcHeader = deserializer.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(packageMetaData, deserializer.getSummaryMap()).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(), org.bimserver.database.OldQuery.getDefault());
revision.setService(service);
}
}
newRevisionAdded.setRevision(revision);
newRevisionAdded.setProject(project);
newRevisionAdded.setAccessMethod(getAccessMethod());
if (nrConcreteRevisionsBefore != 0) {
// There already was a revision, lets delete it (only when not merging)
concreteRevision.setClear(true);
}
getDatabaseSession().addPostCommitAction(new PostCommitAction() {
@Override
public void execute() throws UserException {
try (DatabaseSession tmpSession = getBimServer().getDatabase().createSession(OperationType.POSSIBLY_WRITE)) {
Project project = tmpSession.get(poid, OldQuery.getDefault());
project.setCheckinInProgress(0);
tmpSession.store(project);
tmpSession.commit();
} catch (BimserverDatabaseException e) {
LOGGER.error("", e);
} catch (ServiceException e) {
LOGGER.error("", e);
}
if (finalReport != null) {
byte[] htmlBytes = finalReport.toHtml().getBytes(Charsets.UTF_8);
byte[] jsonBytes = finalReport.toJson().toString().getBytes(Charsets.UTF_8);
try (DatabaseSession tmpSession = getBimServer().getDatabase().createSession(OperationType.POSSIBLY_WRITE)) {
AddGeometryReports addGeometryReports = new AddGeometryReports(tmpSession, AccessMethod.INTERNAL, htmlBytes, jsonBytes, finalReport.getTimeToGenerateMs(), authorization.getUoid(), revision.getOid());
try {
tmpSession.executeAndCommitAction(addGeometryReports);
} catch (ServerException e1) {
LOGGER.error("", e1);
}
} catch (BimserverDatabaseException e1) {
LOGGER.error("", e1);
}
}
getBimServer().getNotificationsManager().notify(new NewRevisionNotification(getBimServer(), project.getOid(), revision.getOid(), authorization));
}
});
getDatabaseSession().store(concreteRevision);
getDatabaseSession().store(project);
} catch (Throwable e) {
try (DatabaseSession tmpSession = getBimServer().getDatabase().createSession(OperationType.POSSIBLY_WRITE)) {
Project project = tmpSession.get(poid, OldQuery.getDefault());
project.setCheckinInProgress(0);
tmpSession.store(project);
try {
tmpSession.commit();
} catch (ServiceException e2) {
LOGGER.error("", e2);
}
} catch (BimserverDatabaseException e1) {
LOGGER.error("", e1);
}
if (e instanceof BimserverDatabaseException) {
throw (BimserverDatabaseException) e;
}
if (e instanceof UserException) {
throw (UserException) e;
}
throw new UserException("[" + fileName + "] " + e.getMessage(), e);
}
return concreteRevision;
}
use of org.bimserver.shared.exceptions.ServiceException in project BIMserver by opensourceBIM.
the class Migrator method migrate.
public Schema migrate() throws MigrationException, InconsistentModelsException {
DatabaseSession session = database.createSession(OperationType.POSSIBLY_WRITE);
try {
Schema schema = migrate(session);
session.commit();
return schema;
} catch (BimserverDatabaseException e) {
throw new MigrationException(e);
} catch (ServiceException e) {
throw new MigrationException(e);
} finally {
session.close();
}
}
Aggregations