use of org.bimserver.models.store.ModelCheckerInstance in project BIMserver by opensourceBIM.
the class ServiceImpl method addModelChecker.
@Override
public Long addModelChecker(SModelCheckerInstance modelCheckerInstance) throws UserException, ServerException {
requireAdminAuthenticationAndRunningServer();
DatabaseSession session = getBimServer().getDatabase().createSession();
try {
ModelCheckerInstance convert = getBimServer().getSConverter().convertFromSObject(modelCheckerInstance, session);
return session.executeAndCommitAction(new AddModelCheckerDatabaseAction(session, getInternalAccessMethod(), convert));
} catch (Exception e) {
return handleException(e);
} finally {
session.close();
}
}
use of org.bimserver.models.store.ModelCheckerInstance in project BIMserver by opensourceBIM.
the class CheckinDatabaseAction method execute.
@Override
public ConcreteRevision execute() throws UserException, BimserverDatabaseException {
try {
bimServer.getCheckinsInProgress().put(poid, getActingUid());
if (fileSize == -1) {
setProgress("Deserializing IFC file...", -1);
} else {
setProgress("Deserializing IFC file...", 0);
}
if (getModel().size() == 0) {
throw new DeserializeException("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 = 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(), 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 (bimServer.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 = bimServer.getRenderEnginePools().getRenderEnginePool(model.getPackageMetaData().getSchema(), defaultRenderEngine.getPluginDescriptor().getPluginClassName(), new PluginConfiguration(defaultRenderEngine.getSettings()));
GenerateGeometryResult generateGeometry = new GeometryGenerator(bimServer).generateGeometry(pool, bimServer.getPluginManager(), getDatabaseSession(), ifcModel, project.getId(), concreteRevision.getId(), true, geometryCache);
concreteRevision.setMinBounds(generateGeometry.getMinBoundsAsVector3f());
concreteRevision.setMaxBounds(generateGeometry.getMaxBoundsAsVector3f());
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<EClass, Long> startOids = getDatabaseSession().getStartOids();
if (startOids == null) {
throw new BimserverDatabaseException("No objects changed");
}
int s = 0;
for (EClass eClass : eClasses) {
if (!DatabaseSession.perRecordVersioning(eClass)) {
s++;
}
}
ByteBuffer buffer = ByteBuffer.allocate(8 * s);
buffer.order(ByteOrder.LITTLE_ENDIAN);
for (EClass eClass : eClasses) {
long oid = startOids.get(eClass);
if (!DatabaseSession.perRecordVersioning(eClass)) {
buffer.putLong(oid);
}
}
concreteRevision.setOidCounters(buffer.array());
if (ifcModel != null) {
getDatabaseSession().store(ifcModel.getValues(), project.getId(), concreteRevision.getId());
}
getDatabaseSession().addPostCommitAction(new PostCommitAction() {
@Override
public void execute() throws UserException {
bimServer.getCheckinsInProgress().remove(poid);
bimServer.getNotificationsManager().notify(new NewRevisionNotification(bimServer, project.getOid(), revision.getOid(), authorization));
}
});
getDatabaseSession().store(concreteRevision);
getDatabaseSession().store(project);
} catch (Throwable e) {
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.models.store.ModelCheckerInstance in project BIMserver by opensourceBIM.
the class UpdateModelCheckerDatabaseAction method execute.
@Override
public Void execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
ModelCheckerInstance modelCheckerInstance = getIdEObject();
ModelCheckerPlugin modelCheckerPlugin = bimServer.getPluginManager().getModelCheckerPlugin(modelCheckerInstance.getModelCheckerPluginClassName(), true);
if (modelCheckerPlugin == null) {
throw new UserException("Model Checker Plugin \"" + modelCheckerInstance.getModelCheckerPluginClassName() + "\" not found/enabled");
}
super.execute();
return null;
}
use of org.bimserver.models.store.ModelCheckerInstance in project BIMserver by opensourceBIM.
the class RemoveModelCheckerFromProjectDatabaseAction method execute.
@Override
public Boolean execute() throws UserException, BimserverDatabaseException, BimserverLockConflictException {
ModelCheckerInstance modelCheckerInstance = getDatabaseSession().get(mcoid, OldQuery.getDefault());
Project project = getDatabaseSession().get(poid, OldQuery.getDefault());
project.getModelCheckers().remove(modelCheckerInstance);
getDatabaseSession().store(project);
return true;
}
use of org.bimserver.models.store.ModelCheckerInstance in project BIMserver by opensourceBIM.
the class ValidateModelCheckerDatabaseAction method execute.
@Override
public Void execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
ModelCheckerInstance modelCheckerInstance = getDatabaseSession().get(modelCheckerInstanceOid, OldQuery.getDefault());
ModelCheckerPlugin modelCheckerPlugin = bimServer.getPluginManager().getModelCheckerPlugin(modelCheckerInstance.getModelCheckerPluginClassName(), true);
if (modelCheckerPlugin == null) {
throw new UserException("Model Checker Plugin \"" + modelCheckerInstance.getModelCheckerPluginClassName() + "\" not found/enabled");
}
// ModelChecker modelChecker = modelCheckerPlugin.createModelChecker(null);
// try {
// byte[] result = modelChecker.compile(modelCheckerInstance.getCode());
modelCheckerInstance.setValid(true);
// modelCheckerInstance.setCompiled(result);
getDatabaseSession().store(modelCheckerInstance);
// }
return null;
}
Aggregations