Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

Commit

Permalink
Revert "Revert "ECP-776: adds service to query documents for invoice.""
Browse files Browse the repository at this point in the history
This reverts commit 6230c2c.
  • Loading branch information
danhaywood committed Oct 30, 2018
1 parent 6230c2c commit 897c6aa
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
*
* Copyright 2012-2014 Eurocommercial Properties NV
*
*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.estatio.module.capex.restapi;

import java.util.List;
import java.util.Optional;

import javax.inject.Inject;

import com.google.common.io.BaseEncoding;

import org.apache.isis.applib.annotation.Action;
import org.apache.isis.applib.annotation.DomainService;
import org.apache.isis.applib.annotation.NatureOfService;
import org.apache.isis.applib.annotation.ParameterLayout;
import org.apache.isis.applib.annotation.SemanticsOf;
import org.apache.isis.applib.services.dto.DtoMappingHelper;

import org.incode.module.document.dom.impl.docs.Document;
import org.incode.module.document.dom.impl.paperclips.Paperclip;
import org.incode.module.document.dom.impl.paperclips.PaperclipRepository;

import org.estatio.canonical.documents.v2.DocumentNature;
import org.estatio.canonical.documents.v2.DocumentType;
import org.estatio.canonical.documents.v2.DocumentsDto;
import org.estatio.module.lease.dom.invoicing.InvoiceForLease;
import org.estatio.module.lease.dom.invoicing.InvoiceForLeaseRepository;

@DomainService(
nature = NatureOfService.VIEW_REST_ONLY,
objectType = "incodeDocuments.DocumentService"
)
public class DocumentServiceRestApi {


@Action(semantics = SemanticsOf.SAFE)
public DocumentsDto findDocuments(
@ParameterLayout(named = "invoiceNumber")
final String invoiceNumber,
@ParameterLayout(named = "year")
final int year
) {
final Optional<InvoiceForLease> invoiceIfAny =
invoiceForLeaseRepository.findInvoiceByInvoiceNumber(invoiceNumber, year);
final DocumentsDto documentsDto = new DocumentsDto();
invoiceIfAny.ifPresent(
invoiceForLease -> {
final List<Paperclip> paperclips = paperclipRepository.findByAttachedTo(invoiceForLease);
paperclips.stream()
.map(Paperclip::getDocument)
.filter(Document.class::isInstance)
.map(Document.class::cast)
.forEach(document -> {
final DocumentType documentDto = new DocumentType();
documentDto.setSelf(mappingHelper.oidDtoFor(document));
documentDto.setName(document.getName());
documentDto.setMimeType(document.getMimeType());
documentDto.setNature(natureOf(document));
switch (documentDto.getNature()) {
case BLOB:
final byte[] bytes = document.asBytes();
final String base64EncodedBytes = BaseEncoding.base64().encode(bytes);
documentDto.setBlobBytesBase64Encoded(base64EncodedBytes);
break;
case CLOB:
documentDto.setClobChars(document.asChars());
break;
}
documentsDto.getDocuments().add(documentDto);
});
});
return documentsDto;
}

private DocumentNature natureOf(final Document document) {
if (document == null || document.getSort() == null) return null;
return document.getSort().isBytes()
? DocumentNature.BLOB
: DocumentNature.CLOB;
}

@Inject
InvoiceForLeaseRepository invoiceForLeaseRepository;

@Inject
PaperclipRepository paperclipRepository;

@Inject
DtoMappingHelper mappingHelper;


}
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,9 @@ public List<InvoiceForLease> findInvoicesByInvoiceNumber(
@Nullable
@ParameterLayout(describedAs = "Invoice numbers are reset each year")
final Integer year) {
return invoiceRepository.findMatchingInvoiceNumber(invoiceNumber).stream()
.filter(InvoiceForLease.class::isInstance)
.map(InvoiceForLease.class::cast)
.filter(i -> {
final LocalDate codaValDate = i.getCodaValDate();
return year == null || codaValDate == null || codaValDate.getYear() == year;
})
.collect(Collectors.toList());
return invoiceForLeaseRepository.findInvoicesByInvoiceNumber(invoiceNumber, year);
}

public Integer default1FindInvoicesByInvoiceNumber() {
return clockService.now().getYear();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
package org.estatio.module.lease.dom.invoicing;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import javax.inject.Inject;

import org.joda.time.LocalDate;

Expand All @@ -31,17 +35,18 @@

import org.incode.module.communications.dom.impl.commchannel.CommunicationChannel;

import org.estatio.module.base.dom.UdoDomainRepositoryAndFactory;
import org.estatio.module.agreement.dom.Agreement;
import org.estatio.module.lease.dom.settings.LeaseInvoicingSettingsService;
import org.estatio.module.asset.dom.FixedAsset;
import org.estatio.module.base.dom.UdoDomainRepositoryAndFactory;
import org.estatio.module.currency.dom.Currency;
import org.estatio.module.invoice.dom.Invoice;
import org.estatio.module.invoice.dom.InvoiceRepository;
import org.estatio.module.invoice.dom.InvoiceStatus;
import org.estatio.module.invoice.dom.PaymentMethod;
import org.estatio.module.lease.dom.AgreementRoleCommunicationChannelTypeEnum;
import org.estatio.module.lease.dom.LeaseAgreementRoleTypeEnum;
import org.estatio.module.lease.dom.Lease;
import org.estatio.module.lease.dom.LeaseAgreementRoleTypeEnum;
import org.estatio.module.lease.dom.settings.LeaseInvoicingSettingsService;
import org.estatio.module.party.dom.Party;

@DomainService(repositoryFor = InvoiceForLease.class, nature = NatureOfService.DOMAIN)
Expand Down Expand Up @@ -253,6 +258,34 @@ public void removeRuns(InvoiceCalculationParameters parameters) {
}
}

@Programmatic
public List<InvoiceForLease> findInvoicesByInvoiceNumber(
final String invoiceNumber,
final Integer yearIfAny) {
return invoiceRepository.findMatchingInvoiceNumber(invoiceNumber).stream()
.filter(InvoiceForLease.class::isInstance)
.map(InvoiceForLease.class::cast)
.filter(i -> {
final LocalDate codaValDate = i.getCodaValDate();
return yearIfAny == null || codaValDate == null || codaValDate.getYear() == yearIfAny;
})
.collect(Collectors.toList());
}

@Programmatic
public Optional<InvoiceForLease> findInvoiceByInvoiceNumber(
final String invoiceNumber,
final Integer year) {
return invoiceRepository.findMatchingInvoiceNumber(invoiceNumber).stream()
.filter(InvoiceForLease.class::isInstance)
.map(InvoiceForLease.class::cast)
.filter(i -> {
final LocalDate codaValDate = i.getCodaValDate();
return codaValDate != null && codaValDate.getYear() == year;
})
.findFirst();
}

@javax.inject.Inject
FactoryService factoryService;

Expand All @@ -263,4 +296,7 @@ public void removeRuns(InvoiceCalculationParameters parameters) {
@javax.inject.Inject
LeaseInvoicingSettingsService settingsService;

@Inject
InvoiceRepository invoiceRepository;

}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ language governing permissions and limitations under the License.
-->
<incode-platform.version>1.16.2.20181013-1017-b9a0574e</incode-platform.version>

<estatio-canonical.version>2.0.0-M1.20180706-1047-f6fd67fd</estatio-canonical.version>
<estatio-canonical.version>2.0.0-M1.20181026-1704-823dbee2</estatio-canonical.version>

<maven-checkstyle-plugin.configLocation>${project.basedir}/codequality/checkstyle.xml</maven-checkstyle-plugin.configLocation>
<maven-pmd-plugin.ruleset>${project.basedir}/codequality/pmd.xml</maven-pmd-plugin.ruleset>
Expand Down

0 comments on commit 897c6aa

Please sign in to comment.