use of org.bimserver.plugins.PluginConfiguration in project BIMserver by opensourceBIM.
the class ServiceImpl method checkinInternal.
private Long checkinInternal(Long topicId, final Long poid, final String comment, Long deserializerOid, Long fileSize, String fileName, InputStream originalInputStream, Boolean merge, Boolean sync, final DatabaseSession session, String username, String userUsername, Project project, Path file, long newServiceId) throws BimserverDatabaseException, UserException, IOException, DeserializeException, CannotBeScheduledException {
if (getBimServer().getCheckinsInProgress().containsKey(poid)) {
throw new UserException("Checkin in progress on this project, please try again later");
}
getBimServer().getCheckinsInProgress().put(poid, getAuthorization().getUoid());
DeserializerPluginConfiguration deserializerPluginConfiguration = session.get(StorePackage.eINSTANCE.getDeserializerPluginConfiguration(), deserializerOid, OldQuery.getDefault());
if (deserializerPluginConfiguration == null) {
throw new UserException("Deserializer with oid " + deserializerOid + " not found");
} else {
PluginBundleVersion pluginBundleVersion = deserializerPluginConfiguration.getPluginDescriptor().getPluginBundleVersion();
Plugin plugin = getBimServer().getPluginManager().getPlugin(deserializerPluginConfiguration.getPluginDescriptor().getPluginClassName(), true);
if (plugin != null) {
if (plugin instanceof DeserializerPlugin) {
DeserializerPlugin deserializerPlugin = (DeserializerPlugin) plugin;
ObjectType settings = deserializerPluginConfiguration.getSettings();
Deserializer deserializer = deserializerPlugin.createDeserializer(new PluginConfiguration(settings));
OutputStream outputStream = Files.newOutputStream(file);
InputStream inputStream = new MultiplexingInputStream(originalInputStream, outputStream);
deserializer.init(getBimServer().getDatabase().getMetaDataManager().getPackageMetaData(project.getSchema()));
IfcModelInterface model = null;
try {
model = deserializer.read(inputStream, fileName, fileSize, null);
} finally {
inputStream.close();
}
CheckinDatabaseAction checkinDatabaseAction = new CheckinDatabaseAction(getBimServer(), null, getInternalAccessMethod(), poid, getAuthorization(), model, comment, fileName, merge, newServiceId);
LongCheckinAction longAction = new LongCheckinAction(topicId, getBimServer(), username, userUsername, getAuthorization(), checkinDatabaseAction);
getBimServer().getLongActionManager().start(longAction);
if (sync) {
longAction.waitForCompletion();
}
return longAction.getProgressTopic().getKey().getId();
} else if (plugin instanceof StreamingDeserializerPlugin) {
StreamingDeserializerPlugin streaminDeserializerPlugin = (StreamingDeserializerPlugin) plugin;
ObjectType settings = deserializerPluginConfiguration.getSettings();
StreamingDeserializer streamingDeserializer = streaminDeserializerPlugin.createDeserializer(new PluginConfiguration(settings));
streamingDeserializer.init(getBimServer().getDatabase().getMetaDataManager().getPackageMetaData(project.getSchema()));
RestartableInputStream restartableInputStream = new RestartableInputStream(originalInputStream, file);
StreamingCheckinDatabaseAction checkinDatabaseAction = new StreamingCheckinDatabaseAction(getBimServer(), null, getInternalAccessMethod(), poid, getAuthorization(), comment, fileName, restartableInputStream, streamingDeserializer, fileSize, newServiceId, pluginBundleVersion);
LongStreamingCheckinAction longAction = new LongStreamingCheckinAction(topicId, getBimServer(), username, userUsername, getAuthorization(), checkinDatabaseAction);
getBimServer().getLongActionManager().start(longAction);
if (sync) {
longAction.waitForCompletion();
}
return longAction.getProgressTopic().getKey().getId();
} else {
throw new UserException("No (enabled) (streaming) deserializer found with oid " + deserializerOid);
}
} else {
throw new UserException("No (enabled) (streaming) deserializer found with oid " + deserializerOid);
}
}
}
use of org.bimserver.plugins.PluginConfiguration 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.plugins.PluginConfiguration in project BIMserver by opensourceBIM.
the class DownloadCompareDatabaseAction method getModelCompare.
public org.bimserver.plugins.modelcompare.ModelCompare getModelCompare() throws ModelCompareException, BimserverDatabaseException {
Revision revision1 = getDatabaseSession().get(roid1, OldQuery.getDefault());
Revision revision2 = getDatabaseSession().get(roid2, OldQuery.getDefault());
PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(revision1.getProject().getSchema());
if (revision1.getProject().getSchema().equals(revision2.getProject().getSchema())) {
ModelComparePluginConfiguration modelCompareObject = getDatabaseSession().get(StorePackage.eINSTANCE.getModelComparePluginConfiguration(), mcid, OldQuery.getDefault());
if (modelCompareObject != null) {
ModelComparePlugin modelComparePlugin = getBimServer().getPluginManager().getModelComparePlugin(modelCompareObject.getPluginDescriptor().getPluginClassName(), true);
if (modelComparePlugin != null) {
org.bimserver.plugins.modelcompare.ModelCompare modelCompare = modelComparePlugin.createModelCompare(new PluginConfiguration(modelCompareObject.getSettings()), packageMetaData);
return modelCompare;
} else {
throw new ModelCompareException("No Model Compare found " + modelCompareObject.getPluginDescriptor().getPluginClassName());
}
} else {
throw new ModelCompareException("No configured Model Compare found");
}
} else {
throw new ModelCompareException("Schemas not the same");
}
}
use of org.bimserver.plugins.PluginConfiguration in project BIMserver by opensourceBIM.
the class GetSerializerByContentTypeDatabaseAction method execute.
@Override
public SerializerPluginConfiguration execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
for (SerializerPluginConfiguration serializerPluginConfiguration : getDatabaseSession().getAllOfType(StorePackage.eINSTANCE.getSerializerPluginConfiguration(), SerializerPluginConfiguration.class, OldQuery.getDefault())) {
PluginConfiguration pluginConfiguration = new PluginConfiguration(serializerPluginConfiguration.getSettings());
String string = pluginConfiguration.getString(SerializerPlugin.CONTENT_TYPE);
if (string != null && string.equals(contentType)) {
return serializerPluginConfiguration;
}
}
return null;
}
use of org.bimserver.plugins.PluginConfiguration in project BIMserver by opensourceBIM.
the class CompareDatabaseAction method getModelCompare.
public org.bimserver.plugins.modelcompare.ModelCompare getModelCompare() throws ModelCompareException, BimserverDatabaseException {
Revision revision1 = getDatabaseSession().get(roid1, OldQuery.getDefault());
Revision revision2 = getDatabaseSession().get(roid2, OldQuery.getDefault());
PackageMetaData packageMetaData = bimServer.getMetaDataManager().getPackageMetaData(revision1.getProject().getSchema());
if (revision1.getProject().getSchema().equals(revision2.getProject().getSchema())) {
ModelComparePluginConfiguration modelCompareObject = getDatabaseSession().get(StorePackage.eINSTANCE.getModelComparePluginConfiguration(), mcid, OldQuery.getDefault());
if (modelCompareObject != null) {
ModelComparePlugin modelComparePlugin = bimServer.getPluginManager().getModelComparePlugin(modelCompareObject.getPluginDescriptor().getPluginClassName(), true);
if (modelComparePlugin != null) {
org.bimserver.plugins.modelcompare.ModelCompare modelCompare = modelComparePlugin.createModelCompare(new PluginConfiguration(modelCompareObject.getSettings()), packageMetaData);
return modelCompare;
} else {
throw new ModelCompareException("No Model Compare found " + modelCompareObject.getPluginDescriptor().getPluginClassName());
}
} else {
throw new ModelCompareException("No configured Model Compare found");
}
} else {
throw new ModelCompareException("Not the same schema");
}
}
Aggregations