use of org.apache.isis.applib.annotation.Action in project estatio by estatio.
the class Document_delete method $$.
@Action(semantics = SemanticsOf.IDEMPOTENT_ARE_YOU_SURE, domainEvent = ActionDomainEvent.class)
@ActionLayout(cssClassFa = "trash")
public Object $$() {
List<Object> attachedToList = Lists.newArrayList();
// links from this document to other objects
List<Paperclip> paperclips = paperclipRepository.findByDocument(document);
for (Paperclip paperclip : paperclips) {
final Object attachedTo = paperclip.getAttachedTo();
attachedToList.add(attachedTo);
paperclipRepository.delete(paperclip);
}
// links from other documents to this document
paperclips = paperclipRepository.findByAttachedTo(document);
for (Paperclip paperclip : paperclips) {
paperclipRepository.delete(paperclip);
}
documentRepository.delete(document);
// if was only attached to a single object, then return; otherwise return null.
return attachedToList.size() == 1 ? attachedToList.get(0) : null;
}
use of org.apache.isis.applib.annotation.Action in project estatio by estatio.
the class FakeScheduler method runBackgroundCommands.
@Action(semantics = SemanticsOf.NON_IDEMPOTENT)
public void runBackgroundCommands(@ParameterLayout(named = "Wait for (ms)") final Integer waitFor) throws InterruptedException {
List<CommandJdo> commands = backgroundCommandRepository.findBackgroundCommandsNotYetStarted();
if (commands.isEmpty()) {
throw new IllegalStateException("There are no commands not yet started");
}
transactionService.nextTransaction();
BackgroundCommandExecutionFromBackgroundCommandServiceJdo backgroundExec = new BackgroundCommandExecutionFromBackgroundCommandServiceJdo();
final SimpleSession session = new SimpleSession("scheduler_user", new String[] { "admin_role" });
final Thread thread = new Thread(() -> backgroundExec.execute(session, null));
thread.start();
thread.join(waitFor);
commands = backgroundCommandRepository.findBackgroundCommandsNotYetStarted();
if (!commands.isEmpty()) {
throw new IllegalStateException("There are still " + commands.size() + " not yet started");
}
}
use of org.apache.isis.applib.annotation.Action in project estatio by estatio.
the class DemoInvoice_simulateRenderAsDoc method $$.
@Action(semantics = SemanticsOf.NON_IDEMPOTENT)
@ActionLayout(contributed = Contributed.AS_ACTION)
@MemberOrder(name = "documents", sequence = "1")
public Document $$(@Parameter(fileAccept = "application/pdf") final Blob document, @Parameter(optionality = Optionality.OPTIONAL) @ParameterLayout(named = "File name") final String fileName) throws IOException {
String name = determineName(document, fileName);
final DocumentType documentType = findDocumentType(DocumentType_and_DocumentTemplates_createSome.DOC_TYPE_REF_INVOICE);
final Document receiptDoc = documentRepository.create(documentType, AT_PATH, name, document.getMimeType().getBaseType());
// unlike documents that are generated from a template (where we call documentTemplate#render), in this case
// we have the actual bytes; so we just set up the remaining state of the document manually.
receiptDoc.setRenderedAt(clockService.nowAsDateTime());
receiptDoc.setState(DocumentState.RENDERED);
receiptDoc.setSort(DocumentSort.BLOB);
receiptDoc.setBlobBytes(document.getBytes());
paperclipRepository.attach(receiptDoc, ROLE_NAME, invoice);
return receiptDoc;
}
use of org.apache.isis.applib.annotation.Action in project estatio by estatio.
the class Order_recategorize method act.
@Action(semantics = SemanticsOf.IDEMPOTENT_ARE_YOU_SURE)
@ActionLayout(cssClassFa = "mail-reply", cssClass = "btn-danger")
public Document act(@Nullable final String comment) {
Document document = lookupPdf();
document.setType(DocumentTypeData.INCOMING.findUsing(documentTypeRepository));
stateTransitionService.trigger(document, IncomingDocumentCategorisationStateTransition.class, IncomingDocumentCategorisationStateTransitionType.RESET, comment, null);
// use events to cascade delete, eg paperclips and state transitions/tasks
orderRepository.delete(order);
return document;
}
use of org.apache.isis.applib.annotation.Action in project estatio by estatio.
the class Occupancy method remove.
@Action(semantics = SemanticsOf.NON_IDEMPOTENT_ARE_YOU_SURE, domainEvent = Occupancy.RemoveEvent.class)
public Object remove() {
Lease lease = getLease();
remove(this);
return lease;
}
Aggregations