use of org.bimserver.models.store.Project in project BIMserver by opensourceBIM.
the class ServiceImpl method addProject.
@Override
public SProject addProject(String projectName, String schema) throws ServerException, UserException {
requireRealUserAuthentication();
DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.POSSIBLY_WRITE);
try {
BimDatabaseAction<Project> action = new AddProjectDatabaseAction(getBimServer(), session, getInternalAccessMethod(), projectName, schema, getAuthorization());
return getBimServer().getSConverter().convertToSObject(session.executeAndCommitAction(action));
} catch (Exception e) {
return handleException(e);
} finally {
session.close();
}
}
use of org.bimserver.models.store.Project in project BIMserver by opensourceBIM.
the class CommitTransactionDatabaseAction method execute.
@Override
public ConcreteRevision execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
Project project = getProjectByPoid(longTransaction.getPoid());
User user = getUserByUoid(authorization.getUoid());
if (project == null) {
throw new UserException("Project with poid " + longTransaction.getPoid() + " 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");
}
long size = 0;
Revision previousRevision = project.getLastRevision();
ConcreteRevision previousConcreteRevision = null;
if (previousRevision != null) {
previousConcreteRevision = previousRevision.getConcreteRevisions().get(0);
}
if (project.getLastRevision() != null) {
size += project.getLastRevision().getSize();
}
for (Change change : longTransaction.getChanges()) {
if (change instanceof CreateObjectChange) {
size++;
} else if (change instanceof RemoveObjectChange) {
size--;
}
}
Revision oldLastRevision = project.getLastRevision();
CreateRevisionResult result = createNewConcreteRevision(getDatabaseSession(), size, project, user, comment.trim());
ConcreteRevision concreteRevision = result.getConcreteRevision();
if (previousConcreteRevision != null) {
concreteRevision.setIfcHeader(previousConcreteRevision.getIfcHeader());
}
revision = concreteRevision.getRevisions().get(0);
project.setLastRevision(revision);
final NewRevisionAdded newRevisionAdded = getDatabaseSession().create(NewRevisionAdded.class);
newRevisionAdded.setDate(new Date());
newRevisionAdded.setExecutor(user);
newRevisionAdded.setRevision(concreteRevision.getRevisions().get(0));
newRevisionAdded.setProject(project);
newRevisionAdded.setAccessMethod(getAccessMethod());
OidCounters originalOidCounters = null;
PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(project.getSchema());
if (oldLastRevision != null) {
int highestStopId = AbstractDownloadDatabaseAction.findHighestStopRid(project, oldLastRevision.getLastConcreteRevision());
OldQuery query = new OldQuery(longTransaction.getPackageMetaData(), project.getId(), oldLastRevision.getId(), -1, Deep.YES, highestStopId);
originalOidCounters = query.updateOidCounters(oldLastRevision.getLastConcreteRevision(), getDatabaseSession());
} else {
originalOidCounters = new OidCounters();
}
getDatabaseSession().addPostCommitAction(new PostCommitAction() {
@Override
public void execute() throws UserException {
getBimServer().getNotificationsManager().notify(new SConverter().convertToSObject(newRevisionAdded));
try {
getBimServer().getLongTransactionManager().remove(longTransaction.getTid());
} catch (NoTransactionException e) {
LOGGER.error("", e);
}
}
});
SummaryMap summaryMap = null;
if (oldLastRevision != null && oldLastRevision.getConcreteRevisions().size() == 1 && oldLastRevision.getConcreteRevisions().get(0).getSummary() != null) {
summaryMap = new SummaryMap(packageMetaData, oldLastRevision.getConcreteRevisions().get(0).getSummary());
} else {
summaryMap = new SummaryMap(packageMetaData);
}
// First create all new objects
Transaction transaction = new Transaction(getBimServer(), previousRevision, project, concreteRevision, getDatabaseSession());
for (Change change : longTransaction.getChanges()) {
if (change instanceof CreateObjectChange) {
try {
CreateObjectChange createObjectChange = (CreateObjectChange) change;
change.execute(transaction);
getDatabaseSession().addStartOid(createObjectChange.geteClass(), createObjectChange.getOid());
} catch (IOException | QueryException e) {
e.printStackTrace();
}
summaryMap.add(((CreateObjectChange) change).geteClass(), 1);
}
}
// Then do the rest
for (Change change : longTransaction.getChanges()) {
if (!(change instanceof CreateObjectChange)) {
if (change instanceof RemoveObjectChange) {
summaryMap.remove(((RemoveObjectChange) change).geteClass(), 1);
}
try {
change.execute(transaction);
} catch (IOException e) {
e.printStackTrace();
} catch (QueryException e) {
e.printStackTrace();
}
}
}
for (HashMapVirtualObject object : transaction.getCreated()) {
getDatabaseSession().save(object);
}
for (HashMapVirtualObject object : transaction.getUpdated()) {
getDatabaseSession().save(object, concreteRevision.getId());
}
for (HashMapVirtualObject object : transaction.getDeleted()) {
getDatabaseSession().delete(object, concreteRevision.getId());
}
setProgress("Generating inverses/opposites...", -1);
Revision newRevision = result.getRevisions().get(0);
long newRoid = newRevision.getOid();
try {
fixInverses(packageMetaData, newRoid, summaryMap.getSummaryMap());
} catch (QueryException | IOException e1) {
e1.printStackTrace();
}
int highestStopId = AbstractDownloadDatabaseAction.findHighestStopRid(concreteRevision.getProject(), concreteRevision);
QueryContext queryContext = new QueryContext(getDatabaseSession(), packageMetaData, project.getId(), concreteRevision.getId(), concreteRevision.getRevisions().get(0).getOid(), concreteRevision.getOid(), highestStopId);
Map<String, Long> startOids = getDatabaseSession().getStartOids();
if (startOids == null) {
throw new BimserverDatabaseException("No objects changed");
}
for (EClass eClass : packageMetaData.getEClasses()) {
if (startOids.containsKey(eClass.getEPackage().getName() + "." + eClass.getName())) {
long oid = startOids.get(eClass.getEPackage().getName() + "." + eClass.getName());
if (!DatabaseSession.perRecordVersioning(eClass)) {
originalOidCounters.putIfAbsent(eClass, oid);
}
}
}
queryContext.setOidCounters(originalOidCounters);
concreteRevision.setOidCounters(originalOidCounters == null ? null : originalOidCounters.getBytes());
if (getBimServer().getServerSettingsCache().getServerSettings().isGenerateGeometryOnCheckin()) {
if (regenerateAllGeometry) {
setProgress("Generating Geometry...", -1);
try {
GeometryGenerationReport report = new GeometryGenerationReport();
report.setOriginalDeserializer("No deserializer, low level call");
report.setOriginalIfcFileName("No file, low level call");
report.setOriginalIfcFileSize(-1);
StreamingGeometryGenerator streamingGeometryGenerator = new StreamingGeometryGenerator(getBimServer(), null, -1L, report);
GenerateGeometryResult generateGeometry = streamingGeometryGenerator.generateGeometry(authorization.getUoid(), getDatabaseSession(), queryContext, summaryMap.count());
concreteRevision.setMultiplierToMm(generateGeometry.getMultiplierToMm());
concreteRevision.setBounds(generateGeometry.getBounds());
concreteRevision.setBoundsUntransformed(generateGeometry.getBoundsUntransformed());
generateDensityAndBounds(result, generateGeometry, concreteRevision);
final GeometryGenerationReport finalReport = report;
getDatabaseSession().addPostCommitAction(new PostCommitAction() {
@Override
public void execute() throws UserException {
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));
}
});
} catch (GeometryGeneratingException e) {
throw new UserException(e);
}
revision.setHasGeometry(true);
} else {
if (previousRevision != null) {
byte[] htmlBytes = null;
byte[] jsonBytes = null;
long timeToGenerate = -1;
for (ExtendedData previousExtendedData : previousRevision.getExtendedData()) {
ExtendedDataSchema previousSchema = previousExtendedData.getSchema();
if (previousSchema.getName().contentEquals("GEOMETRY_GENERATION_REPORT_HTML_1_1")) {
htmlBytes = previousExtendedData.getFile().getData();
} else if (previousSchema.getName().contentEquals("GEOMETRY_GENERATION_REPORT_JSON_1_1")) {
jsonBytes = previousExtendedData.getFile().getData();
}
}
byte[] finalHtmlBytes = htmlBytes;
byte[] finalJsonBytes = jsonBytes;
getDatabaseSession().addPostCommitAction(new PostCommitAction() {
public void execute() throws UserException {
try (DatabaseSession tmpSession = getBimServer().getDatabase().createSession(OperationType.POSSIBLY_WRITE)) {
AddGeometryReports addGeometryReports = new AddGeometryReports(tmpSession, AccessMethod.INTERNAL, finalHtmlBytes, finalJsonBytes, timeToGenerate, authorization.getUoid(), revision.getOid());
try {
tmpSession.executeAndCommitAction(addGeometryReports);
} catch (ServerException e1) {
LOGGER.error("", e1);
}
} catch (BimserverDatabaseException e1) {
LOGGER.error("", e1);
}
}
});
concreteRevision.setMultiplierToMm(previousConcreteRevision.getMultiplierToMm());
concreteRevision.setBounds(previousConcreteRevision.getBounds());
concreteRevision.setBoundsUntransformed(previousConcreteRevision.getBoundsUntransformed());
newRevision.setBounds(previousRevision.getBounds());
newRevision.setBoundsUntransformed(previousRevision.getBoundsUntransformed());
newRevision.setBoundsMm(previousRevision.getBoundsMm());
newRevision.setBoundsUntransformedMm(previousRevision.getBoundsUntransformedMm());
// TODO validate this, contains ids?
newRevision.setDensityCollection(previousRevision.getDensityCollection());
revision.setHasGeometry(true);
}
}
}
concreteRevision.setSummary(summaryMap.toRevisionSummary(getDatabaseSession()));
getDatabaseSession().store(concreteRevision);
getDatabaseSession().store(project);
return concreteRevision;
}
use of org.bimserver.models.store.Project in project BIMserver by opensourceBIM.
the class AddProjectDatabaseAction method execute.
@Override
public Project execute() throws UserException, BimserverDatabaseException, BimserverLockConflictException {
User actingUser = getUserByUoid(authorization.getUoid());
String trimmedName = name.trim();
if (trimmedName.equals("")) {
throw new UserException("Invalid project name");
}
final Project project = getDatabaseSession().create(Project.class);
Project parentProject = null;
if (parentPoid != -1) {
parentProject = getProjectByPoid(parentPoid);
project.setParent(parentProject);
parentProject.getSubProjects().add(project);
getDatabaseSession().store(parentProject);
}
if (actingUser.getUserType() != UserType.SYSTEM) {
if (parentPoid == -1 && actingUser.getUserType() != UserType.ADMIN && !bimServer.getServerSettingsCache().getServerSettings().isAllowUsersToCreateTopLevelProjects()) {
throw new UserException("Only administrators can create new projects");
}
}
if (project.getParent() == null) {
for (Project p : getProjectsByName(trimmedName)) {
if (p.getParent() == null) {
throw new UserException("Project name must be unique");
}
}
} else {
Project parent = project.getParent();
for (Project subProject : parent.getSubProjects()) {
if (subProject != project && subProject.getName().equals(trimmedName)) {
throw new UserException("Project name must be unique within parent project (" + parent.getName() + ")");
}
}
project.setGeoTag(parent.getGeoTag());
}
if (schema == null || (!schema.toLowerCase().equals("ifc2x3tc1") && !schema.toLowerCase().equals("ifc4"))) {
throw new UserException("Invalid schema, the only 2 valid options are: \"ifc2x3tc1\" and \"ifc4\", not \"" + this.schema + "\"");
}
schema = schema.toLowerCase();
final NewProjectAdded newProjectAdded = getDatabaseSession().create(NewProjectAdded.class);
newProjectAdded.setDate(new Date());
newProjectAdded.setExecutor(actingUser);
newProjectAdded.setParentProject(parentProject);
newProjectAdded.setProject(project);
newProjectAdded.setAccessMethod(getAccessMethod());
getDatabaseSession().addPostCommitAction(new PostCommitAction() {
@Override
public void execute() throws UserException {
bimServer.getNotificationsManager().notify(new NewProjectNotification(bimServer, project.getOid()));
// bimServer.getNotificationsManager().notify(new SConverter().convertToSObject(newProjectAdded));
}
});
project.setSendEmailOnNewRevision(bimServer.getServerSettingsCache().getServerSettings().isSendEmailOnNewRevision());
project.setId(getDatabaseSession().newPid());
project.setName(trimmedName);
project.setSchema(schema);
// project.getHasAuthorizedUsers().add(getAdminUser());
project.getHasAuthorizedUsers().add(actingUser);
project.setCreatedBy(actingUser);
project.setCreatedDate(new Date());
project.setDescription("");
project.setExportLengthMeasurePrefix(SIPrefix.METER);
if (project.getParent() == null) {
GeoTag geoTag = getDatabaseSession().create(GeoTag.class);
geoTag.setEnabled(false);
project.setGeoTag(geoTag);
getDatabaseSession().store(geoTag);
} else {
GeoTag geoTag = parentProject.getGeoTag();
project.setGeoTag(geoTag);
getDatabaseSession().store(geoTag);
}
getDatabaseSession().store(project);
getDatabaseSession().store(actingUser);
getDatabaseSession().store(newProjectAdded);
return project;
}
use of org.bimserver.models.store.Project in project BIMserver by opensourceBIM.
the class BranchToNewProjectDatabaseAction method execute.
@Override
public ConcreteRevision execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
Revision oldRevision = getDatabaseSession().get(StorePackage.eINSTANCE.getRevision(), roid, OldQuery.getDefault());
Project oldProject = oldRevision.getProject();
final 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());
if (lastMetaData != null && lastMetaData != packageMetaData) {
throw new UserException("Branching not possible for revision with multiple schemas");
}
IfcModel subModel = new BasicIfcModel(packageMetaData, null);
getDatabaseSession().getMap(subModel, new OldQuery(packageMetaData, subRevision.getProject().getId(), subRevision.getId(), -1, Deep.NO));
subModel.getModelMetaData().setDate(subRevision.getDate());
ifcModelSet.add(subModel);
}
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();
final Project newProject = new AddProjectDatabaseAction(bimServer, getDatabaseSession(), getAccessMethod(), projectName, "ifc2x3tc1", authorization).execute();
// TODO
CheckinDatabaseAction createCheckinAction = new CheckinDatabaseAction(bimServer, getDatabaseSession(), getAccessMethod(), newProject.getOid(), authorization, model, comment, comment, false, -1, -1);
return createCheckinAction.execute();
}
use of org.bimserver.models.store.Project in project BIMserver by opensourceBIM.
the class CheckoutDatabaseAction method execute.
@Override
public IfcModel execute() throws UserException, BimserverDatabaseException, BimserverLockConflictException {
DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm");
User user = getUserByUoid(getAuthorization().getUoid());
Revision revision = getRevisionByRoid(roid);
Project project = revision.getProject();
if (user.getHasRightsOn().contains(project)) {
for (Checkout checkout : revision.getCheckouts()) {
if (checkout.getRevision() == revision && checkout.getUser() == user && checkout.getActive()) {
throw new UserException("This revision has already been checked out by you on " + dateFormat.format(checkout.getDate()));
}
}
for (Checkout checkout : project.getCheckouts()) {
if (checkout.getUser() == user && checkout.getActive()) {
checkout.setActive(false);
Checkout newCheckout = getDatabaseSession().create(Checkout.class);
newCheckout.setActive(true);
newCheckout.setDate(new Date());
newCheckout.setUser(user);
newCheckout.setProject(project);
newCheckout.setRevision(revision);
getDatabaseSession().store(checkout);
getDatabaseSession().store(newCheckout);
getDatabaseSession().store(project);
return realCheckout(project, revision, getDatabaseSession(), user);
}
}
Checkout checkout = getDatabaseSession().create(Checkout.class);
checkout.setActive(true);
checkout.setDate(new Date());
checkout.setUser(user);
checkout.setProject(project);
checkout.setRevision(revision);
getDatabaseSession().store(checkout);
getDatabaseSession().store(project);
return realCheckout(project, revision, getDatabaseSession(), user);
} else {
throw new UserException("Insufficient rights to checkout this project");
}
}
Aggregations