Search in sources :

Example 1 with ApplicationException

use of org.apache.isis.applib.ApplicationException in project estatio by estatio.

the class DocumentTemplate method renderContent.

// endregion
// region > renderContent (programmatic)
@Programmatic
public void renderContent(final Document document, final Object contentDataModel) {
    final String variant = "content";
    final String documentName = document.getName();
    try {
        final DocumentNature inputNature = getContentRenderingStrategy().getInputNature();
        final DocumentNature outputNature = getContentRenderingStrategy().getOutputNature();
        final Renderer renderer = getContentRenderingStrategy().newRenderer();
        switch(inputNature) {
            case BYTES:
                switch(outputNature) {
                    case BYTES:
                        final byte[] renderedBytes = ((RendererFromBytesToBytes) renderer).renderBytesToBytes(getType(), variant, getAtPath(), getVersion(), asBytes(), contentDataModel);
                        final Blob blob = new Blob(documentName, getMimeType(), renderedBytes);
                        document.modifyBlob(blob);
                        return;
                    case CHARACTERS:
                        final String renderedChars = ((RendererFromBytesToChars) renderer).renderBytesToChars(getType(), variant, getAtPath(), getVersion(), asBytes(), contentDataModel);
                        if (renderedChars.length() <= TextType.Meta.MAX_LEN) {
                            document.setTextData(getName(), getMimeType(), renderedChars);
                        } else {
                            final Clob clob = new Clob(documentName, getMimeType(), renderedChars);
                            document.modifyClob(clob);
                        }
                        return;
                    default:
                        // shouldn't happen, above switch statement is complete
                        throw new IllegalArgumentException(String.format("Unknown output DocumentNature '%s'", outputNature));
                }
            case CHARACTERS:
                switch(outputNature) {
                    case BYTES:
                        final byte[] renderedBytes = ((RendererFromCharsToBytes) renderer).renderCharsToBytes(getType(), variant, getAtPath(), getVersion(), asChars(), contentDataModel);
                        final Blob blob = new Blob(documentName, getMimeType(), renderedBytes);
                        document.modifyBlob(blob);
                        return;
                    case CHARACTERS:
                        final String renderedChars = ((RendererFromCharsToChars) renderer).renderCharsToChars(getType(), variant, getAtPath(), getVersion(), asChars(), contentDataModel);
                        if (renderedChars.length() <= TextType.Meta.MAX_LEN) {
                            document.setTextData(getName(), getMimeType(), renderedChars);
                        } else {
                            final Clob clob = new Clob(documentName, getMimeType(), renderedChars);
                            document.modifyClob(clob);
                        }
                        return;
                    default:
                        // shouldn't happen, above switch statement is complete
                        throw new IllegalArgumentException(String.format("Unknown output DocumentNature '%s'", outputNature));
                }
            default:
                // shouldn't happen, above switch statement is complete
                throw new IllegalArgumentException(String.format("Unknown input DocumentNature '%s'", inputNature));
        }
    } catch (IOException e) {
        throw new ApplicationException("Unable to render document template", e);
    }
}
Also used : Blob(org.apache.isis.applib.value.Blob) RendererFromCharsToChars(org.incode.module.document.dom.impl.renderers.RendererFromCharsToChars) TranslatableString(org.apache.isis.applib.services.i18n.TranslatableString) RendererFromCharsToBytes(org.incode.module.document.dom.impl.renderers.RendererFromCharsToBytes) IOException(java.io.IOException) RendererFromBytesToChars(org.incode.module.document.dom.impl.renderers.RendererFromBytesToChars) RendererFromBytesToBytes(org.incode.module.document.dom.impl.renderers.RendererFromBytesToBytes) ApplicationException(org.apache.isis.applib.ApplicationException) Renderer(org.incode.module.document.dom.impl.renderers.Renderer) Clob(org.apache.isis.applib.value.Clob) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 2 with ApplicationException

use of org.apache.isis.applib.ApplicationException in project estatio by estatio.

the class Api method putPropertyPostalAddress.

// //////////////////////////////////////
@ActionSemantics(Of.IDEMPOTENT)
public void putPropertyPostalAddress(@Named("propertyReference") final String propertyReference, @Named("address1") @Optional final String address1, @Named("address2") @Optional final String address2, @Named("city") final String city, @Named("postalCode") @Optional final String postalCode, @Named("stateCode") @Optional final String stateCode, @Named("countryCode") final String countryCode) {
    final Property property = properties.findPropertyByReferenceElseNull(propertyReference);
    if (property == null) {
        throw new ApplicationException(String.format("Property with reference %s not found.", propertyReference));
    }
    final CommunicationChannel comm = communicationChannelContributions.findCommunicationChannelForType(property, null);
    if (comm == null) {
        communicationChannelContributions.newPostal(property, CommunicationChannelType.POSTAL_ADDRESS, countries.findCountry(countryCode), states.findState(stateCode), address1, address2, null, postalCode, city);
    }
}
Also used : ApplicationException(org.apache.isis.applib.ApplicationException) Property(org.estatio.dom.asset.Property)

Example 3 with ApplicationException

use of org.apache.isis.applib.ApplicationException in project estatio by estatio.

the class LeaseTermForServiceChargeImport method fetchLease.

private Lease fetchLease(final String leaseReference) {
    final Lease lease;
    lease = leaseRepository.findLeaseByReference(leaseReference.trim().replaceAll("~", "+"));
    if (lease == null) {
        throw new ApplicationException(String.format("Lease with reference %s not found.", leaseReference));
    }
    return lease;
}
Also used : ApplicationException(org.apache.isis.applib.ApplicationException) Lease(org.estatio.module.lease.dom.Lease)

Example 4 with ApplicationException

use of org.apache.isis.applib.ApplicationException in project estatio by estatio.

the class LeaseTermImportAbstract method fetchLease.

private Lease fetchLease(final String leaseReference) {
    final Lease lease;
    lease = leaseRepository.findLeaseByReference(leaseReference.trim().replaceAll("~", "+"));
    if (lease == null) {
        throw new ApplicationException(String.format("Lease with reference %s not found.", leaseReference));
    }
    return lease;
}
Also used : ApplicationException(org.apache.isis.applib.ApplicationException) Lease(org.estatio.module.lease.dom.Lease)

Example 5 with ApplicationException

use of org.apache.isis.applib.ApplicationException in project estatio by estatio.

the class CommunicationChannelImport method fetchLease.

private Lease fetchLease(final String leaseReference) {
    final Lease lease;
    lease = leaseRepository.findLeaseByReference(leaseReference.trim().replaceAll("~", "+"));
    if (lease == null) {
        throw new ApplicationException(String.format("Lease with reference %s not found.", leaseReference));
    }
    return lease;
}
Also used : ApplicationException(org.apache.isis.applib.ApplicationException) Lease(org.estatio.module.lease.dom.Lease)

Aggregations

ApplicationException (org.apache.isis.applib.ApplicationException)23 Lease (org.estatio.module.lease.dom.Lease)11 Programmatic (org.apache.isis.applib.annotation.Programmatic)6 Charge (org.estatio.module.charge.dom.Charge)4 Property (org.estatio.module.asset.dom.Property)3 IOException (java.io.IOException)2 Budget (org.estatio.module.budget.dom.budget.Budget)2 BudgetCalculationType (org.estatio.module.budget.dom.budgetcalculation.BudgetCalculationType)2 BudgetItem (org.estatio.module.budget.dom.budgetitem.BudgetItem)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStreamReader (java.io.InputStreamReader)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 DataSource (javax.activation.DataSource)1 HttpHost (org.apache.http.HttpHost)1 StatusLine (org.apache.http.StatusLine)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 HttpGet (org.apache.http.client.methods.HttpGet)1 HttpClientContext (org.apache.http.client.protocol.HttpClientContext)1 Action (org.apache.isis.applib.annotation.Action)1