use of org.bimserver.models.store.Project in project BIMserver by opensourceBIM.
the class ServiceImpl method initiateCheckin.
@Override
public Long initiateCheckin(Long poid, Long deserializerOid) throws ServerException, UserException {
requireAuthenticationAndRunningServer();
ProgressOnProjectTopic progressTopic = getBimServer().getNotificationsManager().createProgressOnProjectTopic(getAuthorization().getUoid(), poid, SProgressTopicType.UPLOAD, "Checkin");
long topicId = progressTopic.getKey().getId();
try (DatabaseSession tmpSession = getBimServer().getDatabase().createSession(OperationType.POSSIBLY_WRITE)) {
Project tmpProject = tmpSession.get(poid, OldQuery.getDefault());
if (tmpProject.getCheckinInProgress() != topicId && tmpProject.getCheckinInProgress() != 0) {
Thread.sleep(1000);
throw new UserException("Checkin in progress on this project (topicId: " + tmpProject.getCheckinInProgress() + "), please try again later");
}
tmpProject.setCheckinInProgress(topicId);
tmpSession.store(tmpProject);
tmpSession.commit();
} catch (BimserverDatabaseException e) {
// TODO
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ServiceException e) {
if (e instanceof UserException) {
throw (UserException) e;
}
e.printStackTrace();
}
final DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.READ_ONLY);
try {
User user = (User) session.get(StorePackage.eINSTANCE.getUser(), getAuthorization().getUoid(), OldQuery.getDefault());
Project project = session.get(poid, OldQuery.getDefault());
if (!getAuthorization().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 (project == null) {
throw new UserException("No project found with poid " + poid);
}
return progressTopic.getKey().getId();
} catch (UserException e) {
throw e;
} catch (Throwable e) {
LOGGER.error("", e);
throw new ServerException(e);
} finally {
session.close();
}
}
use of org.bimserver.models.store.Project in project BIMserver by opensourceBIM.
the class NotificationRegistryServiceImpl method getProgressTopicsOnProject.
@Override
public List<Long> getProgressTopicsOnProject(Long poid) throws ServerException, UserException {
DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.READ_ONLY);
try {
List<Long> list = new ArrayList<Long>();
Project project = session.get(StorePackage.eINSTANCE.getProject(), poid, OldQuery.getDefault());
List<Long> revisionOids = new ArrayList<Long>();
for (Revision revision : project.getRevisions()) {
revisionOids.add(revision.getOid());
}
Set<ProgressTopic> progressOnProjectTopics = getBimServer().getNotificationsManager().getProgressOnProjectTopics(poid, revisionOids);
if (progressOnProjectTopics != null) {
for (ProgressTopic topic : progressOnProjectTopics) {
list.add(topic.getKey().getId());
}
}
return list;
} catch (Exception e) {
return handleException(e);
} finally {
session.close();
}
}
use of org.bimserver.models.store.Project in project BIMserver by opensourceBIM.
the class BimServer method cleanupStaleData.
private void cleanupStaleData() throws BimserverDatabaseException {
LOGGER.info("Checking for stale records, this can take some time...");
long s = System.nanoTime();
try (DatabaseSession session = bimDatabase.createSession(OperationType.POSSIBLY_WRITE)) {
for (Project project : session.getAll(Project.class)) {
if (project.getCheckinInProgress() == 0) {
continue;
}
if (project.getName().equals("INT-Store")) {
continue;
}
int recordsRemoved = 0;
if (project.getRevisions().size() == 0) {
recordsRemoved += checkPidRid(session, project, project.getId(), 0);
} else {
ConcreteRevision lastConcreteRevision = project.getLastConcreteRevision();
if (lastConcreteRevision != null) {
recordsRemoved += checkPidRid(session, project, project.getId(), lastConcreteRevision.getId());
}
}
if (recordsRemoved > 0) {
LOGGER.info("Removed " + recordsRemoved + " stale records for project " + project.getName());
}
project.setCheckinInProgress(0);
session.store(project);
}
session.commit();
} catch (ServiceException e1) {
LOGGER.error("", e1);
}
long e = System.nanoTime();
LOGGER.info("Done checking for stale records (" + ((e - s) / 1000000) + " ms)");
}
use of org.bimserver.models.store.Project in project BIMserver by opensourceBIM.
the class ServiceImpl method getUserRelatedLogs.
@Override
public List<SLogAction> getUserRelatedLogs(Long uoid) throws ServerException, UserException {
DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.READ_ONLY);
try {
List<LogAction> logActions = new ArrayList<LogAction>();
User user = session.get(getAuthorization().getUoid(), OldQuery.getDefault());
IfcModelInterface projectsModel = session.getAllOfType(StorePackage.eINSTANCE.getProject(), OldQuery.getDefault());
logActions.addAll(user.getLogs());
for (IdEObject idEObject : projectsModel.getValues()) {
if (idEObject instanceof Project) {
Project project = (Project) idEObject;
if ((user.getUserType() == UserType.ADMIN || (project.getState() == ObjectState.ACTIVE) && getAuthorization().hasRightsOnProjectOrSuperProjectsOrSubProjects(user, project))) {
logActions.addAll(project.getLogs());
}
}
}
Collections.sort(logActions, new Comparator<LogAction>() {
@Override
public int compare(LogAction o1, LogAction o2) {
return o1.getDate().compareTo(o2.getDate());
}
});
return getBimServer().getSConverter().convertToSListLogAction(logActions);
} catch (Exception e) {
return handleException(e);
} finally {
session.close();
}
}
use of org.bimserver.models.store.Project in project BIMserver by opensourceBIM.
the class ServiceImpl method checkinInitiatedInternalSync.
public SLongActionState checkinInitiatedInternalSync(Long topicId, final Long poid, final String comment, Long deserializerOid, Long fileSize, String fileName, DataHandler dataHandler, Boolean merge, Boolean sync, long newServiceId) throws ServerException, UserException {
requireAuthenticationAndRunningServer();
final DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.POSSIBLY_WRITE);
String username = "Unknown";
String userUsername = "Unknown";
try {
User user = (User) session.get(StorePackage.eINSTANCE.getUser(), getAuthorization().getUoid(), OldQuery.getDefault());
Project project = session.get(poid, OldQuery.getDefault());
if (project == null) {
throw new UserException("No project found with poid " + poid);
}
username = user.getName();
userUsername = user.getUsername();
Path incomingFile = getIncomingFileName(fileName, null, userUsername);
return checkinInternal(topicId, poid, comment, deserializerOid, fileSize, fileName, dataHandler.getInputStream(), merge, sync, session, username, userUsername, project, incomingFile, newServiceId);
} catch (UserException e) {
try {
clearCheckinInProgress(poid);
} catch (BimserverDatabaseException | ServiceException e1) {
LOGGER.error("", e1);
}
throw e;
} catch (Throwable e) {
try {
clearCheckinInProgress(poid);
} catch (BimserverDatabaseException | ServiceException e1) {
LOGGER.error("", e1);
}
LOGGER.error("", e);
throw new ServerException(e);
} finally {
session.close();
}
}
Aggregations