use of org.incode.module.document.dom.impl.applicability.AttachmentAdvisor in project estatio by estatio.
the class DocumentTemplate method newAttachmentAdvisor.
@Programmatic
public AttachmentAdvisor newAttachmentAdvisor(final Object domainObject) {
final Class<?> domainObjectClass = domainObject.getClass();
final com.google.common.base.Optional<Applicability> applicabilityIfAny = FluentIterable.from(getAppliesTo()).filter(applicability -> applies(applicability, domainObjectClass)).first();
if (!applicabilityIfAny.isPresent()) {
return null;
}
final AttachmentAdvisor attachmentAdvisor = (AttachmentAdvisor) classService.instantiate(applicabilityIfAny.get().getAttachmentAdvisorClassName());
serviceRegistry2.injectServicesInto(attachmentAdvisor);
return attachmentAdvisor;
}
use of org.incode.module.document.dom.impl.applicability.AttachmentAdvisor in project estatio by estatio.
the class DocumentTemplate method newAttachmentAdvice.
@Programmatic
public List<AttachmentAdvisor.PaperclipSpec> newAttachmentAdvice(final Document document, final Object domainObject) {
final AttachmentAdvisor attachmentAdvisor = newAttachmentAdvisor(domainObject);
if (attachmentAdvisor == null) {
throw new IllegalStateException(String.format("For domain template %s, could not locate Applicability for domain object: %s", getName(), domainObject.getClass().getName()));
}
final List<AttachmentAdvisor.PaperclipSpec> paperclipSpecs = attachmentAdvisor.advise(this, domainObject, document);
return paperclipSpecs;
}
use of org.incode.module.document.dom.impl.applicability.AttachmentAdvisor in project estatio by estatio.
the class DocumentTemplateForAtPathService method documentTemplatesForCreateAndAttach.
@Programmatic
public List<DocumentTemplate> documentTemplatesForCreateAndAttach(final Object domainObject) {
final List<DocumentTemplate> templates = Lists.newArrayList();
final String atPath = atPathFor(domainObject);
if (atPath == null) {
return templates;
}
final List<DocumentTemplate> templatesForPath = documentTemplateRepository.findByApplicableToAtPath(atPath);
return Lists.newArrayList(templatesForPath.stream().filter(template -> {
final AttachmentAdvisor advisor = template.newAttachmentAdvisor(domainObject);
if (advisor == null) {
return false;
}
// at this stage we are asking the advisor if it would be able to attach a document
// if created. We don't yet have that document, so it is null.
final Document document = null;
final List<AttachmentAdvisor.PaperclipSpec> paperclipSpecs = advisor.advise(template, domainObject, document);
return canCreate(template, paperclipSpecs);
}).collect(Collectors.toList()));
}
Aggregations