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);
}
}
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());
}
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());
}
}
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);
}
}
});
}
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());
}
}
}
Aggregations