use of org.bimserver.models.store.Checkout in project BIMserver by opensourceBIM.
the class GetCheckinWarningsDatabaseAction method checkInterleavingCommits.
private void checkInterleavingCommits(Project project, User user, Set<String> warnings) {
Checkout lastOwnActiveCheckout = null;
for (Checkout checkout : project.getCheckouts()) {
if (checkout.getUser() == user && checkout.getActive()) {
lastOwnActiveCheckout = checkout;
}
}
if (lastOwnActiveCheckout != null) {
Project mainProject = project;
while (mainProject.getParent() != null) {
mainProject = mainProject.getParent();
}
int newRevisionsAfterCheckout = 0;
for (Revision virtualRevision : mainProject.getRevisions()) {
if (lastOwnActiveCheckout.getDate().before(virtualRevision.getDate()) && lastOwnActiveCheckout.getRevision() != virtualRevision) {
newRevisionsAfterCheckout++;
}
}
if (newRevisionsAfterCheckout == 1) {
warnings.add("Warning, after your last checkout of this project (revision " + lastOwnActiveCheckout.getRevision().getId() + "), a new revision has been checked-in");
} else if (newRevisionsAfterCheckout > 1) {
warnings.add("Warning, after your last checkout of this project (revision " + lastOwnActiveCheckout.getRevision().getId() + "), " + newRevisionsAfterCheckout + " new revisions have been checked-in");
}
}
}
use of org.bimserver.models.store.Checkout 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");
}
}
use of org.bimserver.models.store.Checkout in project BIMserver by opensourceBIM.
the class GenericCheckinDatabaseAction method createNewConcreteRevision.
public CreateRevisionResult createNewConcreteRevision(DatabaseSession session, long size, Project project, User user, String comment) throws BimserverDatabaseException, BimserverLockConflictException {
CreateRevisionResult result = new CreateRevisionResult();
ConcreteRevision concreteRevision = getDatabaseSession().create(ConcreteRevision.class);
concreteRevision.setSize(size);
Date date = new Date();
concreteRevision.setDate(date);
concreteRevision.setId(project.getConcreteRevisions().size() + 1);
concreteRevision.setUser(user);
concreteRevision.setProject(project);
project.setLastConcreteRevision(concreteRevision);
Revision newRevision = createNewVirtualRevision(session, project, concreteRevision, comment, date, user, size);
for (Checkout checkout : project.getCheckouts()) {
if (checkout.getUser() == user) {
checkout.setActive(false);
session.store(checkout);
}
}
project.setLastRevision(newRevision);
Project parent = project.getParent();
result.addRevision(newRevision);
while (parent != null) {
Revision revision = getDatabaseSession().create(Revision.class);
result.addRevision(revision);
revision.setComment("generated for subproject " + project.getName() + ", revision " + concreteRevision.getId() + ", by " + user.getName());
revision.setDate(date);
revision.setUser(getSystemUser());
revision.setProject(parent);
if (parent.getLastRevision() != null) {
Revision lastRevision = parent.getLastRevision();
for (ConcreteRevision oldRevision : lastRevision.getConcreteRevisions()) {
if (oldRevision.getProject() != project && oldRevision.getProject() != parent) {
revision.getConcreteRevisions().add(oldRevision);
revision.setSize((revision.getSize() == null ? 0 : revision.getSize()) + oldRevision.getSize());
session.store(revision);
session.store(oldRevision);
}
}
}
revision.getConcreteRevisions().add(concreteRevision);
revision.setSize((revision.getSize() == null ? 0 : revision.getSize()) + concreteRevision.getSize());
revision.setLastConcreteRevision(concreteRevision);
if (parent.getLastRevision() == null) {
revision.setId(1);
} else {
revision.setId(parent.getLastRevision().getId() + 1);
}
parent.setLastRevision(revision);
session.store(revision);
session.store(parent);
parent = parent.getParent();
}
session.store(project);
session.store(user);
session.store(concreteRevision);
result.setConcreteRevision(concreteRevision);
return result;
}
use of org.bimserver.models.store.Checkout in project BIMserver by opensourceBIM.
the class GetAllCheckoutsOfRevisionDatabaseAction method execute.
@Override
public List<Checkout> execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
Revision revision = getRevisionByRoid(roid);
Condition condition = new HasReferenceToCondition(StorePackage.eINSTANCE.getCheckout_Revision(), revision);
return CollectionUtils.mapToList(getDatabaseSession().query(condition, Checkout.class, OldQuery.getDefault()));
}
use of org.bimserver.models.store.Checkout in project BIMserver by opensourceBIM.
the class ServiceImpl method getAllCheckoutsOfProject.
@Override
public List<SCheckout> getAllCheckoutsOfProject(Long poid) throws ServerException, UserException {
requireRealUserAuthentication();
DatabaseSession session = getBimServer().getDatabase().createSession();
try {
BimDatabaseAction<List<Checkout>> action = new GetAllCheckoutsOfProjectDatabaseAction(session, getInternalAccessMethod(), poid, false);
List<Checkout> list = session.executeAndCommitAction(action);
Collections.sort(list, new CheckoutComparator());
return getBimServer().getSConverter().convertToSListCheckout(list);
} catch (Exception e) {
return handleException(e);
} finally {
session.close();
}
}
Aggregations