use of org.apache.isis.applib.annotation.Programmatic 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.annotation.Programmatic 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.annotation.Programmatic in project estatio by estatio.
the class DocumentCreatorService method createDocumentAndAttachPaperclips.
/**
* Replaced by {@link org.incode.module.document.dom.api.DocumentService#createDocumentAndAttachPaperclips(Object, DocumentTemplate)} as formal API.
*
* @param domainObject
* @param template
* @return
*/
@Deprecated
@Programmatic
public Document createDocumentAndAttachPaperclips(final Object domainObject, final DocumentTemplate template) {
final Document createdDocument = template.create(domainObject);
final List<AttachmentAdvisor.PaperclipSpec> paperclipSpecs = template.newAttachmentAdvice(createdDocument, domainObject);
for (AttachmentAdvisor.PaperclipSpec paperclipSpec : paperclipSpecs) {
final String roleName = paperclipSpec.getRoleName();
final Object attachTo = paperclipSpec.getAttachTo();
final Document paperclipSpecCreatedDocument = paperclipSpec.getCreatedDocument();
if (paperclipRepository.canAttach(attachTo)) {
paperclipRepository.attach(paperclipSpecCreatedDocument, roleName, attachTo);
}
}
return createdDocument;
}
use of org.apache.isis.applib.annotation.Programmatic in project estatio by estatio.
the class OrderRepository method create.
@Programmatic
public Order create(final Property property, final String orderNumber, final String sellerOrderReference, final LocalDate entryDate, final LocalDate orderDate, final Party seller, final Party buyer, final String atPath, final OrderApprovalState approvalStateIfAny) {
final Numerator numerator = numeratorRepository.findOrCreateNumerator("Order number", null, "%05d", BigInteger.ZERO, applicationTenancyRepository.findByPath(atPath));
final Order order = new Order(property, orderNumber == null ? numerator.nextIncrementStr() : orderNumber, sellerOrderReference, entryDate, orderDate, seller, buyer, atPath, approvalStateIfAny);
serviceRegistry2.injectServicesInto(order);
repositoryService.persistAndFlush(order);
return order;
}
use of org.apache.isis.applib.annotation.Programmatic in project estatio by estatio.
the class OrderApprovalStateSubscriber method on.
@Programmatic
@com.google.common.eventbus.Subscribe
@org.axonframework.eventhandling.annotation.EventHandler
public void on(Order.ObjectPersistedEvent ev) {
// nb: note that the order at this stage has no items attached to it,
// so there is a limit as to what we can safely do.
// however, it *is* ok to just create the state chart for the domain object.
final Order order = ev.getSource();
OrderApprovalState approvalState = order.getApprovalState();
if (approvalState == OrderApprovalStateTransitionType.INSTANTIATE.getToState()) {
// ie was set in the persisting callback
stateTransitionService.trigger(order, OrderApprovalStateTransitionType.INSTANTIATE, null, null);
}
}
Aggregations