Search in sources :

Example 1 with PartyDto

use of org.estatio.canonical.party.v1.PartyDto in project estatio by estatio.

the class PartyDtoFactory method newDto.

@Programmatic
public PartyDto newDto(final Party party) {
    PartyDto dto = new PartyDto();
    dto.setSelf(mappingHelper.oidDtoFor(party));
    dto.setName(party.getName());
    dto.setReference(party.getReference());
    final SortedSet<CommunicationChannel> postalAddresses = communicationChannelRepository.findByOwnerAndType(party, CommunicationChannelType.POSTAL_ADDRESS);
    final Optional<CommunicationChannel> postalAddressIfAny = postalAddresses.stream().filter(x -> x.isLegal()).findFirst();
    if (postalAddressIfAny.isPresent()) {
        dto.setLegalPostalAddress(mappingHelper.oidDtoFor(postalAddressIfAny.get()));
    }
    return dto;
}
Also used : Inject(javax.inject.Inject) NatureOfService(org.apache.isis.applib.annotation.NatureOfService) Party(org.estatio.module.party.dom.Party) SortedSet(java.util.SortedSet) DtoMappingHelper(org.apache.isis.applib.services.dto.DtoMappingHelper) CommunicationChannel(org.incode.module.communications.dom.impl.commchannel.CommunicationChannel) CommunicationChannelType(org.incode.module.communications.dom.impl.commchannel.CommunicationChannelType) Optional(java.util.Optional) PartyDto(org.estatio.canonical.party.v1.PartyDto) DomainService(org.apache.isis.applib.annotation.DomainService) CommunicationChannelRepository(org.incode.module.communications.dom.impl.commchannel.CommunicationChannelRepository) Programmatic(org.apache.isis.applib.annotation.Programmatic) PartyDto(org.estatio.canonical.party.v1.PartyDto) CommunicationChannel(org.incode.module.communications.dom.impl.commchannel.CommunicationChannel) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 2 with PartyDto

use of org.estatio.canonical.party.v1.PartyDto in project estatio by estatio.

the class PartyDtoFactory_Test method happy_case.

@Test
public void happy_case() throws Exception {
    // given
    final Party p = new Organisation();
    p.setReference("12345678");
    p.setName("New Company");
    // expecting
    final OidDto partyOidDto = new OidDto();
    context.checking(new Expectations() {

        {
            oneOf(mockDtoMappingHelper).oidDtoFor(p);
            will(returnValue(partyOidDto));
            oneOf(mockCommunicationChannelRepository).findByOwnerAndType(p, CommunicationChannelType.POSTAL_ADDRESS);
            will(returnValue(Collections.emptySortedSet()));
        }
    });
    // when
    PartyDto partyDto = partyDtoFactory.newDto(p);
    // and when roundtrip
    String xml = jaxbService.toXml(partyDto);
    PartyDto partyDtoAfter = jaxbService.fromXml(PartyDto.class, xml);
    // then
    assertThat(partyDtoAfter.getName()).isEqualTo(p.getName());
    assertThat(partyDtoAfter.getReference()).isEqualTo(p.getReference());
}
Also used : Expectations(org.jmock.Expectations) OidDto(org.apache.isis.schema.common.v1.OidDto) Party(org.estatio.module.party.dom.Party) Organisation(org.estatio.module.party.dom.Organisation) PartyDto(org.estatio.canonical.party.v1.PartyDto) Test(org.junit.Test)

Aggregations

PartyDto (org.estatio.canonical.party.v1.PartyDto)2 Party (org.estatio.module.party.dom.Party)2 Optional (java.util.Optional)1 SortedSet (java.util.SortedSet)1 Inject (javax.inject.Inject)1 DomainService (org.apache.isis.applib.annotation.DomainService)1 NatureOfService (org.apache.isis.applib.annotation.NatureOfService)1 Programmatic (org.apache.isis.applib.annotation.Programmatic)1 DtoMappingHelper (org.apache.isis.applib.services.dto.DtoMappingHelper)1 OidDto (org.apache.isis.schema.common.v1.OidDto)1 Organisation (org.estatio.module.party.dom.Organisation)1 CommunicationChannel (org.incode.module.communications.dom.impl.commchannel.CommunicationChannel)1 CommunicationChannelRepository (org.incode.module.communications.dom.impl.commchannel.CommunicationChannelRepository)1 CommunicationChannelType (org.incode.module.communications.dom.impl.commchannel.CommunicationChannelType)1 Expectations (org.jmock.Expectations)1 Test (org.junit.Test)1