use of org.apache.isis.applib.annotation.Action in project estatio by estatio.
the class Communication_downloadPdfForPosting method act.
@Action(semantics = SemanticsOf.IDEMPOTENT)
@ActionLayout(named = "Download PDF for posting", cssClassFa = "download")
public Blob act(@ParameterLayout(named = "File name") final String fileName) throws IOException {
// the act of downloading implicitly sends the communication
if (communication.getState() == CommunicationState.PENDING) {
communication.sent();
}
final List<byte[]> pdfBytes = Lists.newArrayList();
final Document primaryDoc = communication.getPrimaryDocument();
appendBytes(primaryDoc, pdfBytes);
// merge any and all attachments
final List<Document> attachedDocuments = findAttachedPdfDocuments();
attachedDocuments.sort(Ordering.natural().onResultOf(Document::getCreatedAt));
for (final Document attachedDoc : attachedDocuments) {
appendBytes(attachedDoc, pdfBytes);
}
final byte[] mergedBytes = pdfBoxService.merge(pdfBytes.toArray(new byte[][] {}));
return new Blob(fileName, DocumentConstants.MIME_TYPE_APPLICATION_PDF, mergedBytes);
}
use of org.apache.isis.applib.annotation.Action in project estatio by estatio.
the class CommunicationChannelOwner_findCommunications method act.
@Action(semantics = SemanticsOf.SAFE, domainEvent = ActionDomainEvent.class)
public List<Communication> act(final LocalDate from, final LocalDate to) {
final DateTime fromDateTime = toDateTime(from);
final DateTime toDateTime = toDateTime(to).plusDays(1);
final List<CommunicationChannelOwnerLink> channelLinks = communicationChannelRepository.findByOwner(communicationChannelOwner);
final List<Communication> communications = Lists.newArrayList();
for (final CommunicationChannelOwnerLink link : channelLinks) {
final List<Communication> comms = communicationRepository.findByCommunicationChannelAndPendingOrCreatedAtBetween(link.getCommunicationChannel(), fromDateTime, toDateTime);
communications.addAll(comms);
}
communications.sort(Communication.Orderings.createdAtDescending);
return communications;
}
use of org.apache.isis.applib.annotation.Action in project estatio by estatio.
the class Document_sendByPost method act.
@Action(semantics = SemanticsOf.NON_IDEMPOTENT, domainEvent = ActionDomainEvent.class)
@ActionLayout(cssClassFa = "envelope-o", contributed = Contributed.AS_ACTION)
public Communication act(@ParameterLayout(named = "to:") final PostalAddress toChannel) throws IOException {
if (this.document.getState() == DocumentState.NOT_RENDERED) {
// this shouldn't happen, but want to fail-fast in case a future programmer calls this directly
throw new IllegalArgumentException("Document is not yet rendered");
}
// create comm and correspondents
final String atPath = document.getAtPath();
final String subject = document.getName();
final Communication communication = communicationRepository.createPostal(subject, atPath, toChannel);
transactionService.flushTransaction();
// attach this "primary" document to the comm
paperclipRepository.attach(this.document, DocumentConstants.PAPERCLIP_ROLE_PRIMARY, communication);
// also copy over as attachments to the comm anything else also attached to original document
final List<Document> communicationAttachments = attachmentProvider.attachmentsFor(document);
for (Document communicationAttachment : communicationAttachments) {
paperclipRepository.attach(communicationAttachment, DocumentConstants.PAPERCLIP_ROLE_ATTACHMENT, communication);
}
transactionService.flushTransaction();
return communication;
}
use of org.apache.isis.applib.annotation.Action in project estatio by estatio.
the class KeyTable method generateItems.
@Action(semantics = SemanticsOf.NON_IDEMPOTENT_ARE_YOU_SURE)
public KeyTable generateItems() {
// delete old items
for (Iterator<KeyItem> it = this.getItems().iterator(); it.hasNext(); ) {
it.next().deleteBudgetKeyItem();
}
/*
create list of input pairs: identifier - sourcevalue
sourcevalue is determined by FoundationValueType
*/
List<Distributable> input = new ArrayList<>();
for (Unit unit : unitRepository.findByProperty(this.getBudget().getProperty())) {
if (unitIntervalValidForThisKeyTable(unit)) {
BigDecimal sourceValue;
if (getFoundationValueType().valueOf(unit) != null) {
sourceValue = getFoundationValueType().valueOf(unit);
} else {
sourceValue = BigDecimal.ZERO;
}
KeyItem newItem = new KeyItem();
newItem.setSourceValue(sourceValue);
newItem.setValue(BigDecimal.ZERO);
newItem.setUnit(unit);
newItem.setKeyTable(this);
persistIfNotAlready(newItem);
input.add(newItem);
}
}
/*
call distribute method
*/
DistributionService distributionService = new DistributionService();
distributionService.distribute(input, getKeyValueMethod().divider(this), getPrecision());
return this;
}
use of org.apache.isis.applib.annotation.Action in project estatio by estatio.
the class KeyTable method remove.
@Action(semantics = SemanticsOf.IDEMPOTENT_ARE_YOU_SURE)
public Budget remove() {
Budget budgetToReturn = getBudget();
repositoryService.removeAndFlush(this);
return budgetToReturn;
}
Aggregations