Search in sources :

Example 21 with ApplicationException

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

the class OccupancyImport 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 22 with ApplicationException

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

the class OccupancyImport method importData.

@Override
@Programmatic
public List<Object> importData(Object previousRow) {
    final Lease lease = fetchLease(leaseReference);
    final Unit unit = unitRepository.findUnitByReference(unitReference);
    if (unitReference != null && unit == null) {
        throw new ApplicationException(String.format("Unit with reference %s not found.", unitReference));
    }
    Occupancy occupancy = occupancyRepository.findByLeaseAndUnitAndStartDate(lease, unit, startDate);
    if (occupancy == null) {
        occupancy = occupancyRepository.newOccupancy(lease, unit, startDate);
    }
    occupancy.setEndDate(endDate);
    occupancy.setUnitSizeName(size);
    occupancy.setBrandName(brand != null ? brand.replaceAll("\\p{C}", "").trim() : null, null, null);
    occupancy.setSectorName(sector);
    occupancy.setActivityName(activity);
    occupancy.setReportTurnover(reportTurnover != null ? Occupancy.OccupancyReportingType.valueOf(reportTurnover) : Occupancy.OccupancyReportingType.NO);
    occupancy.setReportRent(reportRent != null ? Occupancy.OccupancyReportingType.valueOf(reportRent) : Occupancy.OccupancyReportingType.NO);
    occupancy.setReportOCR(reportOCR != null ? Occupancy.OccupancyReportingType.valueOf(reportOCR) : Occupancy.OccupancyReportingType.NO);
    return Lists.newArrayList(occupancy);
}
Also used : ApplicationException(org.apache.isis.applib.ApplicationException) Lease(org.estatio.module.lease.dom.Lease) Occupancy(org.estatio.module.lease.dom.occupancy.Occupancy) Unit(org.estatio.module.asset.dom.Unit) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 23 with ApplicationException

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

the class UrlDownloaderUsingNtlmCredentials method download.

@Override
public byte[] download(final URL url) throws IOException {
    HttpHost target = new HttpHost(url.getHost(), url.getPort(), url.getProtocol());
    // Make sure the same context is used to execute logically related requests
    // (not thread-safe, so need a new one each time)
    HttpClientContext context = HttpClientContext.create();
    context.setCredentialsProvider(credsProvider);
    HttpGet httpGet = new HttpGet(url.getFile());
    try (final CloseableHttpResponse httpResponse = httpclient.execute(target, httpGet, context)) {
        final StatusLine statusLine = httpResponse.getStatusLine();
        if (statusLine == null) {
            throw new ApplicationException(String.format("Could not obtain response statusLine for %s", url.toExternalForm()));
        }
        final int statusCode = statusLine.getStatusCode();
        if (statusCode != 200) {
            // try to read content of entity, but ignore any exceptions
            // because we are simply trying to get extra data to report in the exception below
            InputStreamReader inputStreamReader = null;
            String entityContent = "";
            try {
                inputStreamReader = new InputStreamReader(httpResponse.getEntity().getContent());
                entityContent = CharStreams.toString(inputStreamReader);
            } catch (java.lang.Throwable ex) {
            // ignore
            } finally {
                if (inputStreamReader != null) {
                    try {
                        inputStreamReader.close();
                    } catch (Exception ex) {
                    // ignore
                    }
                }
            }
            throw new ApplicationException(String.format("Failed to download from '%s': %d %s\n%s", url.toExternalForm(), statusCode, statusLine.getReasonPhrase(), entityContent));
        }
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        httpResponse.getEntity().writeTo(baos);
        return baos.toByteArray();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) HttpGet(org.apache.http.client.methods.HttpGet) HttpClientContext(org.apache.http.client.protocol.HttpClientContext) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ApplicationException(org.apache.isis.applib.ApplicationException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) StatusLine(org.apache.http.StatusLine) ApplicationException(org.apache.isis.applib.ApplicationException) HttpHost(org.apache.http.HttpHost) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse)

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