use of org.bimserver.models.store.Project in project BIMserver by opensourceBIM.
the class AddUserToProjectDatabaseAction method execute.
@Override
public Boolean execute() throws UserException, BimserverDatabaseException, BimserverLockConflictException {
final Project project = getProjectByPoid(poid);
User actingUser = getUserByUoid(authorization.getUoid());
if (authorization.hasRightsOnProject(actingUser, project)) {
User user = getUserByUoid(uoid);
project.getHasAuthorizedUsers().add(user);
user.getHasRightsOn().add(project);
final UserAddedToProject userAddedToProject = getDatabaseSession().create(UserAddedToProject.class);
userAddedToProject.setExecutor(actingUser);
userAddedToProject.setDate(new Date());
userAddedToProject.setAccessMethod(getAccessMethod());
userAddedToProject.setUser(user);
userAddedToProject.setProject(project);
getDatabaseSession().addPostCommitAction(new PostCommitAction() {
@Override
public void execute() throws UserException {
bimServer.getNotificationsManager().notify(new SConverter().convertToSObject(userAddedToProject));
}
});
getDatabaseSession().store(user);
getDatabaseSession().store(project);
return true;
} else {
throw new UserException("User has no rights to grant permission on '" + project.getName() + "'");
}
}
use of org.bimserver.models.store.Project in project BIMserver by opensourceBIM.
the class CheckinDatabaseAction method clearCheckinInProgress.
private void clearCheckinInProgress() throws BimserverDatabaseException, ServiceException {
try (DatabaseSession tmpSession = getBimServer().getDatabase().createSession(OperationType.READ_WRITE)) {
Project project = tmpSession.get(poid, OldQuery.getDefault());
project.setCheckinInProgress(0);
tmpSession.store(project);
tmpSession.commit();
}
}
use of org.bimserver.models.store.Project in project BIMserver by opensourceBIM.
the class CreateBaseProjectDatabaseAction method execute.
@Override
public Project execute() throws UserException, BimserverDatabaseException, BimserverLockConflictException {
final Project project = getDatabaseSession().create(Project.class);
project.setName(Database.STORE_PROJECT_NAME);
project.setCreatedDate(new Date());
getDatabaseSession().store(project);
return project;
}
use of org.bimserver.models.store.Project in project BIMserver by opensourceBIM.
the class AddLocalServiceToProjectDatabaseAction method execute.
@Override
public Void execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
Project project = getDatabaseSession().get(StorePackage.eINSTANCE.getProject(), poid, OldQuery.getDefault());
User user = getDatabaseSession().get(StorePackage.eINSTANCE.getUser(), authorization.getUoid(), OldQuery.getDefault());
service.setUser(user);
for (org.bimserver.models.store.Service existing : project.getServices()) {
if (existing.getName().equals(service.getName())) {
throw new UserException("Service name \"" + service.getName() + "\" already used in this project");
}
}
service.setInternalService((InternalServicePluginConfiguration) getDatabaseSession().get(StorePackage.eINSTANCE.getInternalServicePluginConfiguration(), internalServiceOid, OldQuery.getDefault()));
project.getServices().add(service);
service.setProject(project);
getDatabaseSession().store(service);
service.setProfileIdentifier("" + service.getOid());
getDatabaseSession().store(project);
return null;
}
use of org.bimserver.models.store.Project 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();
}
}
Aggregations