Search in sources :

Example 1 with AfterMapping

use of org.mapstruct.AfterMapping in project cals-api by ca-cwds.

the class TrailingSpacesRemovalPostMappingProcessor method apply.

@AfterMapping
protected void apply(@MappingTarget Object object) {
    if (object == null || isCollection(object.getClass())) {
        return;
    }
    try {
        doRemoveTrailingSpaces(object);
        List<Field> allFieldsList = FieldUtils.getAllFieldsList(object.getClass());
        for (Field field : allFieldsList) {
            applyForField(object, field);
        }
    } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
        throw new IllegalStateException(ERROR_MESSAGE, e);
    }
}
Also used : Field(java.lang.reflect.Field) InvocationTargetException(java.lang.reflect.InvocationTargetException) AfterMapping(org.mapstruct.AfterMapping)

Example 2 with AfterMapping

use of org.mapstruct.AfterMapping in project cals-api by ca-cwds.

the class OtherAdultsInPlacementHomeMapper method afterMapping.

@AfterMapping
default void afterMapping(@MappingTarget OtherAdultsInPlacementHome target, OtherAdultDTO otherAdultDTO) {
    StringBuilder nameBuilder = new StringBuilder();
    NamePrefixType namePrefix = otherAdultDTO.getNamePrefix();
    if (namePrefix != null) {
        nameBuilder.append(namePrefix.getValue());
    }
    String firstName = otherAdultDTO.getFirstName();
    if (StringUtils.isNoneEmpty(firstName)) {
        nameBuilder.append(' ').append(firstName);
    }
    String middleName = otherAdultDTO.getMiddleName();
    if (StringUtils.isNoneEmpty(middleName)) {
        nameBuilder.append(' ').append(middleName);
    }
    String lastName = otherAdultDTO.getLastName();
    if (StringUtils.isNoneEmpty(lastName)) {
        nameBuilder.append(' ').append(lastName);
    }
    NameSuffixType nameSuffix = otherAdultDTO.getNameSuffix();
    if (nameSuffix != null) {
        nameBuilder.append(' ').append(nameSuffix.getValue());
    }
    target.setOthAdltnm(nameBuilder.toString());
}
Also used : NamePrefixType(gov.ca.cwds.cals.persistence.model.calsns.dictionaries.NamePrefixType) NameSuffixType(gov.ca.cwds.cals.persistence.model.calsns.dictionaries.NameSuffixType) AfterMapping(org.mapstruct.AfterMapping)

Example 3 with AfterMapping

use of org.mapstruct.AfterMapping in project cals-api by ca-cwds.

the class PersonMapper method fillAge.

@AfterMapping
default void fillAge(@MappingTarget PersonDTO personDTO) {
    LocalDate dateOfBirth = personDTO.getDateOfBirth();
    if (dateOfBirth != null) {
        Period period = Period.between(dateOfBirth, LocalDate.now());
        personDTO.setAge(period.getYears());
    }
}
Also used : Period(java.time.Period) LocalDate(java.time.LocalDate) AfterMapping(org.mapstruct.AfterMapping)

Example 4 with AfterMapping

use of org.mapstruct.AfterMapping in project cals-api by ca-cwds.

the class FacilityChildMapper method after.

@AfterMapping
default void after(@MappingTarget FacilityChildDTO facilityChildDto, Client client) {
    Optional.ofNullable(client).ifPresent(c -> {
        Set<? extends BasePlacementEpisode> placementEpisodes = c.getPlacementEpisodes();
        if (!placementEpisodes.isEmpty()) {
            FacilityChildMapper facilityChildMapper = Mappers.getMapper(FacilityChildMapper.class);
            BasePlacementEpisode placementEpisode = placementEpisodes.iterator().next();
            County county = placementEpisode.getCounty();
            facilityChildMapper.toFacilityChildDTO(facilityChildDto, county);
            Set<? extends BaseOutOfHomePlacement> outOfHomePlacements = placementEpisode.getOutOfHomePlacements();
            if (!outOfHomePlacements.isEmpty()) {
                BaseOutOfHomePlacement outOfHomePlacement = outOfHomePlacements.iterator().next();
                facilityChildMapper.toFacilityChildDTO(facilityChildDto, outOfHomePlacement);
            }
        }
    });
}
Also used : BaseOutOfHomePlacement(gov.ca.cwds.data.legacy.cms.entity.BaseOutOfHomePlacement) BasePlacementEpisode(gov.ca.cwds.data.legacy.cms.entity.BasePlacementEpisode) County(gov.ca.cwds.data.legacy.cms.entity.syscodes.County) AfterMapping(org.mapstruct.AfterMapping)

Example 5 with AfterMapping

use of org.mapstruct.AfterMapping in project workbench by all-of-us.

the class DataSetMapper method populateFromSourceDbObject.

@AfterMapping
default void populateFromSourceDbObject(@MappingTarget DbDataset targetDb, @Context DbDataset srcDbDataset, @Context Clock clock) {
    targetDb.setInvalid(srcDbDataset == null ? false : srcDbDataset.getInvalid());
    Timestamp now = new Timestamp(clock.instant().toEpochMilli());
    if (srcDbDataset == null) {
        targetDb.setInvalid(false);
        targetDb.setCreationTime(now);
        targetDb.setLastModifiedTime(now);
    } else {
        targetDb.setCreationTime(srcDbDataset.getCreationTime());
        targetDb.setDataSetId(srcDbDataset.getDataSetId());
        targetDb.setCreatorId(srcDbDataset.getCreatorId());
        targetDb.setLastModifiedTime(now);
        if (targetDb.getValues().isEmpty()) {
            // In case of rename, dataSetRequest does not have cohort/Concept ID information
            targetDb.setConceptSetIds(srcDbDataset.getConceptSetIds());
            targetDb.setCohortIds(srcDbDataset.getCohortIds());
            targetDb.setValues(srcDbDataset.getValues());
            targetDb.setIncludesAllParticipants(srcDbDataset.getIncludesAllParticipants());
            targetDb.setPrePackagedConceptSet(srcDbDataset.getPrePackagedConceptSet());
        }
    }
}
Also used : Timestamp(java.sql.Timestamp) AfterMapping(org.mapstruct.AfterMapping)

Aggregations

AfterMapping (org.mapstruct.AfterMapping)12 Links (de.otto.edison.hal.Links)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 BigDecimal (java.math.BigDecimal)2 EdisonHalAppender (sonia.scm.web.EdisonHalAppender)2 S3bucketDataStorage (com.epam.pipeline.entity.datastorage.aws.S3bucketDataStorage)1 NamePrefixType (gov.ca.cwds.cals.persistence.model.calsns.dictionaries.NamePrefixType)1 NameSuffixType (gov.ca.cwds.cals.persistence.model.calsns.dictionaries.NameSuffixType)1 AddressDTO (gov.ca.cwds.cals.service.dto.AddressDTO)1 FacilityAddressDTO (gov.ca.cwds.cals.service.dto.FacilityAddressDTO)1 BaseOutOfHomePlacement (gov.ca.cwds.data.legacy.cms.entity.BaseOutOfHomePlacement)1 BasePlacementEpisode (gov.ca.cwds.data.legacy.cms.entity.BasePlacementEpisode)1 County (gov.ca.cwds.data.legacy.cms.entity.syscodes.County)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 Timestamp (java.sql.Timestamp)1 LocalDate (java.time.LocalDate)1 Period (java.time.Period)1