Search in sources :

Example 6 with Checkout

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");
        }
    }
}
Also used : Project(org.bimserver.models.store.Project) Checkout(org.bimserver.models.store.Checkout) Revision(org.bimserver.models.store.Revision)

Example 7 with Checkout

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");
    }
}
Also used : Project(org.bimserver.models.store.Project) User(org.bimserver.models.store.User) Checkout(org.bimserver.models.store.Checkout) Revision(org.bimserver.models.store.Revision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) UserException(org.bimserver.shared.exceptions.UserException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 8 with Checkout

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;
}
Also used : Project(org.bimserver.models.store.Project) Checkout(org.bimserver.models.store.Checkout) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) Revision(org.bimserver.models.store.Revision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) Date(java.util.Date)

Example 9 with Checkout

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()));
}
Also used : Condition(org.bimserver.database.query.conditions.Condition) HasReferenceToCondition(org.bimserver.database.query.conditions.HasReferenceToCondition) Checkout(org.bimserver.models.store.Checkout) Revision(org.bimserver.models.store.Revision) HasReferenceToCondition(org.bimserver.database.query.conditions.HasReferenceToCondition)

Example 10 with Checkout

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();
    }
}
Also used : SCheckout(org.bimserver.interfaces.objects.SCheckout) Checkout(org.bimserver.models.store.Checkout) GetAllCheckoutsOfProjectDatabaseAction(org.bimserver.database.actions.GetAllCheckoutsOfProjectDatabaseAction) DatabaseSession(org.bimserver.database.DatabaseSession) CheckoutComparator(org.bimserver.webservices.CheckoutComparator) ArrayList(java.util.ArrayList) List(java.util.List) EList(org.eclipse.emf.common.util.EList) IOException(java.io.IOException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) SerializerException(org.bimserver.plugins.serializers.SerializerException) BcfException(org.opensourcebim.bcf.BcfException) UserException(org.bimserver.shared.exceptions.UserException) CannotBeScheduledException(org.bimserver.longaction.CannotBeScheduledException) DeserializeException(org.bimserver.plugins.deserializers.DeserializeException) ServerException(org.bimserver.shared.exceptions.ServerException) MessagingException(javax.mail.MessagingException) AddressException(javax.mail.internet.AddressException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MalformedURLException(java.net.MalformedURLException)

Aggregations

Checkout (org.bimserver.models.store.Checkout)10 UserException (org.bimserver.shared.exceptions.UserException)5 IOException (java.io.IOException)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 MalformedURLException (java.net.MalformedURLException)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 MessagingException (javax.mail.MessagingException)4 AddressException (javax.mail.internet.AddressException)4 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)4 DatabaseSession (org.bimserver.database.DatabaseSession)4 SCheckout (org.bimserver.interfaces.objects.SCheckout)4 CannotBeScheduledException (org.bimserver.longaction.CannotBeScheduledException)4 Project (org.bimserver.models.store.Project)4 Revision (org.bimserver.models.store.Revision)4 DeserializeException (org.bimserver.plugins.deserializers.DeserializeException)4 SerializerException (org.bimserver.plugins.serializers.SerializerException)4 ServerException (org.bimserver.shared.exceptions.ServerException)4 CheckoutComparator (org.bimserver.webservices.CheckoutComparator)4 EList (org.eclipse.emf.common.util.EList)4