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;
}
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));
}
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;
}
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());
}
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());
}
}
Aggregations