Search in sources :

Example 1 with Bookmark

use of org.apache.isis.applib.services.bookmark.Bookmark in project estatio by estatio.

the class PaperclipRepository method attach.

// endregion
// region > attach (programmatic)
/**
 * This is an idempotent operation.
 */
@Programmatic
public Paperclip attach(final DocumentAbstract documentAbstract, final String roleName, final Object attachTo) {
    Paperclip paperclip = findByDocumentAndAttachedToAndRoleName(documentAbstract, attachTo, roleName);
    if (paperclip != null) {
        return paperclip;
    }
    final Class<? extends Paperclip> subtype = subtypeClassFor(attachTo);
    paperclip = repositoryService.instantiate(subtype);
    paperclip.setDocument(documentAbstract);
    paperclip.setRoleName(roleName);
    if (documentAbstract instanceof Document) {
        final Document document = (Document) documentAbstract;
        paperclip.setDocumentCreatedAt(document.getCreatedAt());
    }
    if (!repositoryService.isPersistent(attachTo)) {
        transactionService.flushTransaction();
    }
    final Bookmark bookmark = bookmarkService.bookmarkFor(attachTo);
    paperclip.setAttachedTo(attachTo);
    paperclip.setAttachedToStr(bookmark.toString());
    repositoryService.persistAndFlush(paperclip);
    return paperclip;
}
Also used : Bookmark(org.apache.isis.applib.services.bookmark.Bookmark) Document(org.incode.module.document.dom.impl.docs.Document) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 2 with Bookmark

use of org.apache.isis.applib.services.bookmark.Bookmark in project estatio by estatio.

the class PaperclipRepository method findByDocumentAndAttachedTo.

// endregion
// region > findByDocumentAndAttachedTo (programmatic)
@Programmatic
public List<Paperclip> findByDocumentAndAttachedTo(final DocumentAbstract<?> document, final Object attachedTo) {
    if (document == null) {
        return null;
    }
    if (attachedTo == null) {
        return null;
    }
    final Bookmark bookmark = bookmarkService.bookmarkFor(attachedTo);
    if (bookmark == null) {
        return null;
    }
    final String attachedToStr = bookmark.toString();
    return repositoryService.allMatches(new QueryDefault<>(Paperclip.class, "findByDocumentAndAttachedTo", "document", document, "attachedToStr", attachedToStr));
}
Also used : Bookmark(org.apache.isis.applib.services.bookmark.Bookmark) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 3 with Bookmark

use of org.apache.isis.applib.services.bookmark.Bookmark in project estatio by estatio.

the class NumeratorRepository_Test method setup.

@Before
public void setup() {
    propertyBookmark = new Bookmark("PROP", "123");
    applicationTenancy = new ApplicationTenancy();
    applicationTenancy.setPath("/");
    context.checking(new Expectations() {

        {
            allowing(mockBookmarkService).bookmarkFor(mockProperty);
            will(returnValue(propertyBookmark));
        }
    });
    numeratorRepository = new NumeratorRepository() {

        @Override
        protected <T> T firstMatch(Query<T> query) {
            finderInteraction = new FinderInteraction(query, FinderMethod.FIRST_MATCH);
            return null;
        }

        @Override
        protected List<Numerator> allInstances() {
            finderInteraction = new FinderInteraction(null, FinderMethod.ALL_INSTANCES);
            return null;
        }

        @Override
        protected <T> List<T> allMatches(Query<T> query) {
            finderInteraction = new FinderInteraction(query, FinderMethod.ALL_MATCHES);
            return null;
        }
    };
    numeratorRepository.bookmarkService = mockBookmarkService;
}
Also used : Expectations(org.jmock.Expectations) Bookmark(org.apache.isis.applib.services.bookmark.Bookmark) List(java.util.List) ApplicationTenancy(org.isisaddons.module.security.dom.tenancy.ApplicationTenancy) FinderInteraction(org.incode.module.unittestsupport.dom.repo.FinderInteraction) Before(org.junit.Before)

Example 4 with Bookmark

use of org.apache.isis.applib.services.bookmark.Bookmark in project estatio by estatio.

the class NumeratorRepository method findFirstNumeratorForObjectTypeMatchingAppTenancyPath.

private Numerator findFirstNumeratorForObjectTypeMatchingAppTenancyPath(final String numeratorName, final Object scopedToIfAny, final ApplicationTenancy applicationTenancy) {
    final Bookmark bookmark = getBookmarkService().bookmarkFor(scopedToIfAny);
    final String objectType = bookmark.getObjectType();
    return firstMatch("findByNameAndObjectTypeAndApplicationTenancyPath", "name", numeratorName, "objectType", objectType, "applicationTenancyPath", applicationTenancy == null ? "/" : applicationTenancy.getPath());
}
Also used : Bookmark(org.apache.isis.applib.services.bookmark.Bookmark)

Example 5 with Bookmark

use of org.apache.isis.applib.services.bookmark.Bookmark in project estatio by estatio.

the class NumeratorRepository method findNumerator.

@Programmatic
public Numerator findNumerator(final String numeratorName, final Object scopedToIfAny, final ApplicationTenancy applicationTenancy) {
    if (scopedToIfAny == null) {
        return firstMatch("findByNameAndApplicationTenancyPath", "name", numeratorName, "applicationTenancyPath", applicationTenancy == null ? "/" : applicationTenancy.getPath());
    } else {
        final Bookmark bookmark = getBookmarkService().bookmarkFor(scopedToIfAny);
        final String objectType = bookmark.getObjectType();
        final String objectIdentifier = bookmark.getIdentifier();
        return firstMatch("findByNameAndObjectTypeAndObjectIdentifierAndApplicationTenancyPath", "name", numeratorName, "objectType", objectType, "objectIdentifier", objectIdentifier, "applicationTenancyPath", applicationTenancy == null ? "/" : applicationTenancy.getPath());
    }
}
Also used : Bookmark(org.apache.isis.applib.services.bookmark.Bookmark) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Aggregations

Bookmark (org.apache.isis.applib.services.bookmark.Bookmark)16 Programmatic (org.apache.isis.applib.annotation.Programmatic)9 Document (org.incode.module.document.dom.impl.docs.Document)3 List (java.util.List)1 ParamDto (org.apache.isis.schema.cmd.v1.ParamDto)1 Property (org.estatio.module.asset.dom.Property)1 IncomingDocAsInvoiceViewModel (org.estatio.module.capex.app.invoice.IncomingDocAsInvoiceViewModel)1 IncomingDocAsOrderViewModel (org.estatio.module.capex.app.order.IncomingDocAsOrderViewModel)1 Taxonomy (org.incode.module.classification.dom.impl.category.taxonomy.Taxonomy)1 FinderInteraction (org.incode.module.unittestsupport.dom.repo.FinderInteraction)1 ApplicationTenancy (org.isisaddons.module.security.dom.tenancy.ApplicationTenancy)1 Expectations (org.jmock.Expectations)1 Before (org.junit.Before)1