refactor(client): reformat ClientMapper.java
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
73db4ee114
commit
cfcd24efad
+281
-276
@@ -1,276 +1,281 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.fineract.portfolio.client.mapper;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.Period;
|
||||
import org.apache.fineract.infrastructure.codes.data.CodeValueData;
|
||||
import org.apache.fineract.infrastructure.codes.domain.CodeValue;
|
||||
import org.apache.fineract.infrastructure.core.config.MapstructMapperConfig;
|
||||
import org.apache.fineract.infrastructure.core.data.EnumOptionData;
|
||||
import org.apache.fineract.portfolio.client.data.ClientData;
|
||||
import org.apache.fineract.portfolio.client.data.ClientTimelineData;
|
||||
import org.apache.fineract.portfolio.client.domain.Client;
|
||||
import org.apache.fineract.portfolio.client.domain.ClientEnumerations;
|
||||
import org.apache.fineract.useradministration.domain.AppUser;
|
||||
import org.mapstruct.AfterMapping;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.MappingTarget;
|
||||
import org.mapstruct.Named;
|
||||
|
||||
@Mapper(config = MapstructMapperConfig.class)
|
||||
public interface ClientMapper {
|
||||
|
||||
@Mapping(target = "accountNo", source = "accountNumber")
|
||||
@Mapping(target = "status", source = "source", qualifiedByName = "clientStatusEnum")
|
||||
@Mapping(target = "subStatus", source = "source", qualifiedByName = "clientSubStatusCode")
|
||||
@Mapping(target = "officeId", source = "office.id")
|
||||
@Mapping(target = "officeName", source = "office.name")
|
||||
@Mapping(target = "transferToOfficeId", source = "transferToOffice.id")
|
||||
@Mapping(target = "transferToOfficeName", source = "transferToOffice.name")
|
||||
@Mapping(target = "externalId", source = "externalId")
|
||||
@Mapping(target = "gender", source = "source", qualifiedByName = "clientGenderCode")
|
||||
@Mapping(target = "salutation", source = "source", qualifiedByName = "salutationCode")
|
||||
@Mapping(target = "salutationOptions", ignore = true)
|
||||
@Mapping(target = "imageId", source = "imageId")
|
||||
@Mapping(target = "staffId", source = "staff.id")
|
||||
@Mapping(target = "staffName", source = "staff.displayName")
|
||||
@Mapping(target = "timeline", source = "source", qualifiedByName = "clientTimelineData")
|
||||
@Mapping(target = "savingsProductId", source = "savingsProductId")
|
||||
@Mapping(target = "savingsProductName", source = "id")
|
||||
@Mapping(target = "savingsAccountId", source = "savingsAccountId")
|
||||
@Mapping(target = "clientType", source = "source", qualifiedByName = "clientTypeCode")
|
||||
@Mapping(target = "clientClassification", source = "source", qualifiedByName = "clientClassificationCode")
|
||||
@Mapping(target = "occupationCategory", source = "source", qualifiedByName = "occupationCategoryCode")
|
||||
@Mapping(target = "occupation", source = "source", qualifiedByName = "occupationCode")
|
||||
@Mapping(target = "maritalStatus", source = "source", qualifiedByName = "maritalStatusCode")
|
||||
@Mapping(target = "educationLevel", source = "source", qualifiedByName = "educationLevelCode")
|
||||
@Mapping(target = "degreeQualification", source = "source", qualifiedByName = "degreeQualificationCode")
|
||||
@Mapping(target = "religion", source = "source", qualifiedByName = "religionCode")
|
||||
@Mapping(target = "socialCategory", source = "source", qualifiedByName = "socialCategoryCode")
|
||||
@Mapping(target = "occupationCategoryOptions", ignore = true)
|
||||
@Mapping(target = "occupationOptions", ignore = true)
|
||||
@Mapping(target = "educationLevelOptions", ignore = true)
|
||||
@Mapping(target = "degreeQualificationOptions", ignore = true)
|
||||
@Mapping(target = "religionOptions", ignore = true)
|
||||
@Mapping(target = "socialCategoryOptions", ignore = true)
|
||||
@Mapping(target = "legalForm", source = "source", qualifiedByName = "clientLegalFormEnum")
|
||||
@Mapping(target = "isStaff", source = "source", qualifiedByName = "clientIsStaff")
|
||||
@Mapping(target = "ageYears", ignore = true)
|
||||
@Mapping(target = "ageMonths", ignore = true)
|
||||
@Mapping(target = "ageDays", ignore = true)
|
||||
@Mapping(target = "guardianClientId", source = "source", qualifiedByName = "guardianClientIdValue")
|
||||
@Mapping(target = "guardianClientDisplayName", source = "source", qualifiedByName = "guardianClientDisplayNameValue")
|
||||
@Mapping(target = "imagePresent", ignore = true)
|
||||
@Mapping(target = "officeOptions", ignore = true)
|
||||
@Mapping(target = "staffOptions", ignore = true)
|
||||
@Mapping(target = "narrations", ignore = true)
|
||||
@Mapping(target = "savingProductOptions", ignore = true)
|
||||
@Mapping(target = "savingAccountOptions", ignore = true)
|
||||
@Mapping(target = "genderOptions", ignore = true)
|
||||
@Mapping(target = "clientTypeOptions", ignore = true)
|
||||
@Mapping(target = "clientClassificationOptions", ignore = true)
|
||||
@Mapping(target = "clientNonPersonConstitutionOptions", ignore = true)
|
||||
@Mapping(target = "clientNonPersonMainBusinessLineOptions", ignore = true)
|
||||
@Mapping(target = "clientLegalFormOptions", ignore = true)
|
||||
@Mapping(target = "familyMemberOptions", ignore = true)
|
||||
@Mapping(target = "clientNonPersonDetails", ignore = true)
|
||||
@Mapping(target = "address", ignore = true)
|
||||
@Mapping(target = "isAddressEnabled", ignore = true)
|
||||
@Mapping(target = "datatables", ignore = true)
|
||||
@Mapping(target = "rowIndex", ignore = true)
|
||||
@Mapping(target = "dateFormat", ignore = true)
|
||||
@Mapping(target = "locale", ignore = true)
|
||||
@Mapping(target = "clientTypeId", ignore = true)
|
||||
@Mapping(target = "genderId", ignore = true)
|
||||
@Mapping(target = "clientClassificationId", ignore = true)
|
||||
@Mapping(target = "legalFormId", ignore = true)
|
||||
@Mapping(target = "clientCollateralManagements", ignore = true)
|
||||
@Mapping(target = "groups", ignore = true)
|
||||
ClientData map(Client source);
|
||||
|
||||
@Named("clientTypeCode")
|
||||
default CodeValueData clientTypeCode(Client client) {
|
||||
final CodeValue code = client.getClientType();
|
||||
if (code == null) {
|
||||
return null;
|
||||
}
|
||||
return CodeValueData.instance(code.getId(), code.getLabel());
|
||||
}
|
||||
|
||||
@Named("clientClassificationCode")
|
||||
default CodeValueData clientClassificationCode(Client client) {
|
||||
final CodeValue code = client.getClientClassification();
|
||||
if (code == null) {
|
||||
return null;
|
||||
}
|
||||
return CodeValueData.instance(code.getId(), code.getLabel());
|
||||
}
|
||||
|
||||
@Named("occupationCategoryCode")
|
||||
default CodeValueData occupationCategoryCode(Client client) {
|
||||
final CodeValue code = client.getOccupationCategory();
|
||||
if (code == null) {
|
||||
return null;
|
||||
}
|
||||
return CodeValueData.instance(code.getId(), code.getLabel());
|
||||
}
|
||||
|
||||
@Named("occupationCode")
|
||||
default CodeValueData occupationCode(Client client) {
|
||||
final CodeValue code = client.getOccupation();
|
||||
if (code == null) {
|
||||
return null;
|
||||
}
|
||||
return CodeValueData.instance(code.getId(), code.getLabel());
|
||||
}
|
||||
|
||||
@Named("salutationCode")
|
||||
default CodeValueData salutationCode(Client client) {
|
||||
final CodeValue code = client.getSalutation();
|
||||
if (code == null) {
|
||||
return null;
|
||||
}
|
||||
return CodeValueData.instance(code.getId(), code.getLabel());
|
||||
}
|
||||
|
||||
@Named("maritalStatusCode")
|
||||
default CodeValueData maritalStatusCode(Client client) {
|
||||
final CodeValue code = client.getMaritalStatus();
|
||||
if (code == null) {
|
||||
return null;
|
||||
}
|
||||
return CodeValueData.instance(code.getId(), code.getLabel());
|
||||
}
|
||||
|
||||
@Named("educationLevelCode")
|
||||
default CodeValueData educationLevelCode(Client client) {
|
||||
final CodeValue code = client.getEducationLevel();
|
||||
if (code == null) {
|
||||
return null;
|
||||
}
|
||||
return CodeValueData.instance(code.getId(), code.getLabel());
|
||||
}
|
||||
|
||||
@Named("degreeQualificationCode")
|
||||
default CodeValueData degreeQualificationCode(Client client) {
|
||||
final CodeValue code = client.getDegreeQualification();
|
||||
if (code == null) {
|
||||
return null;
|
||||
}
|
||||
return CodeValueData.instance(code.getId(), code.getLabel());
|
||||
}
|
||||
|
||||
@Named("religionCode")
|
||||
default CodeValueData religionCode(Client client) {
|
||||
final CodeValue code = client.getReligion();
|
||||
if (code == null) {
|
||||
return null;
|
||||
}
|
||||
return CodeValueData.instance(code.getId(), code.getLabel());
|
||||
}
|
||||
|
||||
@Named("socialCategoryCode")
|
||||
default CodeValueData socialCategoryCode(Client client) {
|
||||
final CodeValue code = client.getSocialCategory();
|
||||
if (code == null) {
|
||||
return null;
|
||||
}
|
||||
return CodeValueData.instance(code.getId(), code.getLabel());
|
||||
}
|
||||
|
||||
@Named("clientSubStatusCode")
|
||||
default CodeValueData clientSubStatusCode(Client client) {
|
||||
final CodeValue code = client.getSubStatus();
|
||||
if (code == null) {
|
||||
return null;
|
||||
}
|
||||
return CodeValueData.instance(code.getId(), code.getLabel());
|
||||
}
|
||||
|
||||
@Named("clientGenderCode")
|
||||
default CodeValueData clientGenderCode(Client client) {
|
||||
final CodeValue code = client.getGender();
|
||||
if (code == null) {
|
||||
return null;
|
||||
}
|
||||
return CodeValueData.instance(code.getId(), code.getLabel());
|
||||
}
|
||||
|
||||
@Named("clientLegalFormEnum")
|
||||
default EnumOptionData clientLegalFormEnum(Client client) {
|
||||
return ClientEnumerations.legalForm(client.getLegalForm());
|
||||
}
|
||||
|
||||
@Named("clientStatusEnum")
|
||||
default EnumOptionData clientStatusEnum(Client client) {
|
||||
return ClientEnumerations.status(client.getStatus());
|
||||
}
|
||||
|
||||
@Named("clientTimelineData")
|
||||
default ClientTimelineData clientTimelineData(Client client) {
|
||||
if (client.isClosed()) {
|
||||
final AppUser activatedBy = client.getActivatedBy();
|
||||
if (activatedBy != null) {
|
||||
return new ClientTimelineData(client.getSubmittedOnDate(), null, null, null, client.getActivationDate(),
|
||||
activatedBy.getUsername(), activatedBy.getFirstname(), activatedBy.getLastname(), client.getClosureDate(),
|
||||
client.getClosedBy().getUsername(), client.getClosedBy().getFirstname(), client.getClosedBy().getLastname());
|
||||
} else {
|
||||
return new ClientTimelineData(client.getSubmittedOnDate(), null, null, null, client.getActivationDate(), null, null, null,
|
||||
client.getClosureDate(), client.getClosedBy().getUsername(), client.getClosedBy().getFirstname(),
|
||||
client.getClosedBy().getLastname());
|
||||
|
||||
}
|
||||
} else if (client.isActive()) {
|
||||
return new ClientTimelineData(client.getSubmittedOnDate(), null, null, null, client.getActivationDate(),
|
||||
client.getActivatedBy().getUsername(), client.getActivatedBy().getFirstname(), client.getActivatedBy().getLastname(),
|
||||
null, null, null, null);
|
||||
} else {
|
||||
return new ClientTimelineData(client.getSubmittedOnDate(), null, null, null, null, null, null, null, null, null, null, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Named("clientIsStaff")
|
||||
default Boolean clientIsStaff(Client client) {
|
||||
return Boolean.valueOf(client.isStaff());
|
||||
}
|
||||
|
||||
@Named("guardianClientIdValue")
|
||||
default Long guardianClientIdValue(Client client) {
|
||||
return client.getGuardianClient() != null ? client.getGuardianClient().getId() : null;
|
||||
}
|
||||
|
||||
@Named("guardianClientDisplayNameValue")
|
||||
default String guardianClientDisplayNameValue(Client client) {
|
||||
return client.getGuardianClient() != null ? client.getGuardianClient().getDisplayName() : null;
|
||||
}
|
||||
|
||||
@AfterMapping
|
||||
default void computeAge(Client source, @MappingTarget ClientData target) {
|
||||
final LocalDate dob = source.getDateOfBirth();
|
||||
if (dob != null) {
|
||||
final Period age = Period.between(dob, LocalDate.now());
|
||||
target.setAgeYears(age.getYears());
|
||||
target.setAgeMonths(age.getMonths());
|
||||
target.setAgeDays(age.getDays());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.fineract.portfolio.client.mapper;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.Period;
|
||||
import org.apache.fineract.infrastructure.codes.data.CodeValueData;
|
||||
import org.apache.fineract.infrastructure.codes.domain.CodeValue;
|
||||
import org.apache.fineract.infrastructure.core.config.MapstructMapperConfig;
|
||||
import org.apache.fineract.infrastructure.core.data.EnumOptionData;
|
||||
import org.apache.fineract.portfolio.client.data.ClientData;
|
||||
import org.apache.fineract.portfolio.client.data.ClientTimelineData;
|
||||
import org.apache.fineract.portfolio.client.domain.Client;
|
||||
import org.apache.fineract.portfolio.client.domain.ClientEnumerations;
|
||||
import org.apache.fineract.useradministration.domain.AppUser;
|
||||
import org.mapstruct.AfterMapping;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.MappingTarget;
|
||||
import org.mapstruct.Named;
|
||||
|
||||
@Mapper(config = MapstructMapperConfig.class)
|
||||
public interface ClientMapper {
|
||||
|
||||
@Mapping(target = "accountNo", source = "accountNumber")
|
||||
@Mapping(target = "status", source = "source", qualifiedByName = "clientStatusEnum")
|
||||
@Mapping(target = "subStatus", source = "source", qualifiedByName = "clientSubStatusCode")
|
||||
@Mapping(target = "officeId", source = "office.id")
|
||||
@Mapping(target = "officeName", source = "office.name")
|
||||
@Mapping(target = "transferToOfficeId", source = "transferToOffice.id")
|
||||
@Mapping(target = "transferToOfficeName", source = "transferToOffice.name")
|
||||
@Mapping(target = "externalId", source = "externalId")
|
||||
@Mapping(target = "gender", source = "source", qualifiedByName = "clientGenderCode")
|
||||
@Mapping(target = "salutation", source = "source", qualifiedByName = "salutationCode")
|
||||
@Mapping(target = "salutationOptions", ignore = true)
|
||||
@Mapping(target = "imageId", source = "imageId")
|
||||
@Mapping(target = "staffId", source = "staff.id")
|
||||
@Mapping(target = "staffName", source = "staff.displayName")
|
||||
@Mapping(target = "timeline", source = "source", qualifiedByName = "clientTimelineData")
|
||||
@Mapping(target = "savingsProductId", source = "savingsProductId")
|
||||
@Mapping(target = "savingsProductName", source = "id")
|
||||
@Mapping(target = "savingsAccountId", source = "savingsAccountId")
|
||||
@Mapping(target = "clientType", source = "source", qualifiedByName = "clientTypeCode")
|
||||
@Mapping(target = "clientClassification", source = "source", qualifiedByName = "clientClassificationCode")
|
||||
@Mapping(target = "occupationCategory", source = "source", qualifiedByName = "occupationCategoryCode")
|
||||
@Mapping(target = "occupation", source = "source", qualifiedByName = "occupationCode")
|
||||
@Mapping(target = "maritalStatus", source = "source", qualifiedByName = "maritalStatusCode")
|
||||
@Mapping(target = "educationLevel", source = "source", qualifiedByName = "educationLevelCode")
|
||||
@Mapping(target = "degreeQualification", source = "source", qualifiedByName = "degreeQualificationCode")
|
||||
@Mapping(target = "religion", source = "source", qualifiedByName = "religionCode")
|
||||
@Mapping(target = "socialCategory", source = "source", qualifiedByName = "socialCategoryCode")
|
||||
@Mapping(target = "occupationCategoryOptions", ignore = true)
|
||||
@Mapping(target = "occupationOptions", ignore = true)
|
||||
@Mapping(target = "educationLevelOptions", ignore = true)
|
||||
@Mapping(target = "degreeQualificationOptions", ignore = true)
|
||||
@Mapping(target = "religionOptions", ignore = true)
|
||||
@Mapping(target = "socialCategoryOptions", ignore = true)
|
||||
@Mapping(target = "legalForm", source = "source", qualifiedByName = "clientLegalFormEnum")
|
||||
@Mapping(target = "isStaff", source = "source", qualifiedByName = "clientIsStaff")
|
||||
@Mapping(target = "ageYears", ignore = true)
|
||||
@Mapping(target = "ageMonths", ignore = true)
|
||||
@Mapping(target = "ageDays", ignore = true)
|
||||
@Mapping(target = "guardianClientId", source = "source", qualifiedByName = "guardianClientIdValue")
|
||||
@Mapping(target = "guardianClientDisplayName", source = "source", qualifiedByName = "guardianClientDisplayNameValue")
|
||||
@Mapping(target = "imagePresent", ignore = true)
|
||||
@Mapping(target = "officeOptions", ignore = true)
|
||||
@Mapping(target = "staffOptions", ignore = true)
|
||||
@Mapping(target = "narrations", ignore = true)
|
||||
@Mapping(target = "savingProductOptions", ignore = true)
|
||||
@Mapping(target = "savingAccountOptions", ignore = true)
|
||||
@Mapping(target = "genderOptions", ignore = true)
|
||||
@Mapping(target = "clientTypeOptions", ignore = true)
|
||||
@Mapping(target = "clientClassificationOptions", ignore = true)
|
||||
@Mapping(target = "clientNonPersonConstitutionOptions", ignore = true)
|
||||
@Mapping(target = "clientNonPersonMainBusinessLineOptions", ignore = true)
|
||||
@Mapping(target = "clientLegalFormOptions", ignore = true)
|
||||
@Mapping(target = "familyMemberOptions", ignore = true)
|
||||
@Mapping(target = "clientNonPersonDetails", ignore = true)
|
||||
@Mapping(target = "address", ignore = true)
|
||||
@Mapping(target = "isAddressEnabled", ignore = true)
|
||||
@Mapping(target = "datatables", ignore = true)
|
||||
@Mapping(target = "rowIndex", ignore = true)
|
||||
@Mapping(target = "dateFormat", ignore = true)
|
||||
@Mapping(target = "locale", ignore = true)
|
||||
@Mapping(target = "clientTypeId", ignore = true)
|
||||
@Mapping(target = "genderId", ignore = true)
|
||||
@Mapping(target = "clientClassificationId", ignore = true)
|
||||
@Mapping(target = "legalFormId", ignore = true)
|
||||
@Mapping(target = "clientCollateralManagements", ignore = true)
|
||||
@Mapping(target = "groups", ignore = true)
|
||||
ClientData map(Client source);
|
||||
|
||||
@Named("clientTypeCode")
|
||||
default CodeValueData clientTypeCode(Client client) {
|
||||
final CodeValue code = client.getClientType();
|
||||
if (code == null) {
|
||||
return null;
|
||||
}
|
||||
return CodeValueData.instance(code.getId(), code.getLabel());
|
||||
}
|
||||
|
||||
@Named("clientClassificationCode")
|
||||
default CodeValueData clientClassificationCode(Client client) {
|
||||
final CodeValue code = client.getClientClassification();
|
||||
if (code == null) {
|
||||
return null;
|
||||
}
|
||||
return CodeValueData.instance(code.getId(), code.getLabel());
|
||||
}
|
||||
|
||||
@Named("occupationCategoryCode")
|
||||
default CodeValueData occupationCategoryCode(Client client) {
|
||||
final CodeValue code = client.getOccupationCategory();
|
||||
if (code == null) {
|
||||
return null;
|
||||
}
|
||||
return CodeValueData.instance(code.getId(), code.getLabel());
|
||||
}
|
||||
|
||||
@Named("occupationCode")
|
||||
default CodeValueData occupationCode(Client client) {
|
||||
final CodeValue code = client.getOccupation();
|
||||
if (code == null) {
|
||||
return null;
|
||||
}
|
||||
return CodeValueData.instance(code.getId(), code.getLabel());
|
||||
}
|
||||
|
||||
@Named("salutationCode")
|
||||
default CodeValueData salutationCode(Client client) {
|
||||
final CodeValue code = client.getSalutation();
|
||||
if (code == null) {
|
||||
return null;
|
||||
}
|
||||
return CodeValueData.instance(code.getId(), code.getLabel());
|
||||
}
|
||||
|
||||
@Named("maritalStatusCode")
|
||||
default CodeValueData maritalStatusCode(Client client) {
|
||||
final CodeValue code = client.getMaritalStatus();
|
||||
if (code == null) {
|
||||
return null;
|
||||
}
|
||||
return CodeValueData.instance(code.getId(), code.getLabel());
|
||||
}
|
||||
|
||||
@Named("educationLevelCode")
|
||||
default CodeValueData educationLevelCode(Client client) {
|
||||
final CodeValue code = client.getEducationLevel();
|
||||
if (code == null) {
|
||||
return null;
|
||||
}
|
||||
return CodeValueData.instance(code.getId(), code.getLabel());
|
||||
}
|
||||
|
||||
@Named("degreeQualificationCode")
|
||||
default CodeValueData degreeQualificationCode(Client client) {
|
||||
final CodeValue code = client.getDegreeQualification();
|
||||
if (code == null) {
|
||||
return null;
|
||||
}
|
||||
return CodeValueData.instance(code.getId(), code.getLabel());
|
||||
}
|
||||
|
||||
@Named("religionCode")
|
||||
default CodeValueData religionCode(Client client) {
|
||||
final CodeValue code = client.getReligion();
|
||||
if (code == null) {
|
||||
return null;
|
||||
}
|
||||
return CodeValueData.instance(code.getId(), code.getLabel());
|
||||
}
|
||||
|
||||
@Named("socialCategoryCode")
|
||||
default CodeValueData socialCategoryCode(Client client) {
|
||||
final CodeValue code = client.getSocialCategory();
|
||||
if (code == null) {
|
||||
return null;
|
||||
}
|
||||
return CodeValueData.instance(code.getId(), code.getLabel());
|
||||
}
|
||||
|
||||
@Named("clientSubStatusCode")
|
||||
default CodeValueData clientSubStatusCode(Client client) {
|
||||
final CodeValue code = client.getSubStatus();
|
||||
if (code == null) {
|
||||
return null;
|
||||
}
|
||||
return CodeValueData.instance(code.getId(), code.getLabel());
|
||||
}
|
||||
|
||||
@Named("clientGenderCode")
|
||||
default CodeValueData clientGenderCode(Client client) {
|
||||
final CodeValue code = client.getGender();
|
||||
if (code == null) {
|
||||
return null;
|
||||
}
|
||||
return CodeValueData.instance(code.getId(), code.getLabel());
|
||||
}
|
||||
|
||||
@Named("clientLegalFormEnum")
|
||||
default EnumOptionData clientLegalFormEnum(Client client) {
|
||||
return ClientEnumerations.legalForm(client.getLegalForm());
|
||||
}
|
||||
|
||||
@Named("clientStatusEnum")
|
||||
default EnumOptionData clientStatusEnum(Client client) {
|
||||
return ClientEnumerations.status(client.getStatus());
|
||||
}
|
||||
|
||||
@Named("clientTimelineData")
|
||||
default ClientTimelineData clientTimelineData(Client client) {
|
||||
if (client.isClosed()) {
|
||||
final AppUser activatedBy = client.getActivatedBy();
|
||||
if (activatedBy != null) {
|
||||
return new ClientTimelineData(client.getSubmittedOnDate(), null, null, null, client.getActivationDate(),
|
||||
activatedBy.getUsername(), activatedBy.getFirstname(), activatedBy.getLastname(), client.getClosureDate(),
|
||||
client.getClosedBy().getUsername(), client.getClosedBy().getFirstname(), client.getClosedBy().getLastname());
|
||||
} else {
|
||||
return new ClientTimelineData(client.getSubmittedOnDate(), null, null, null, client.getActivationDate(), null, null, null,
|
||||
client.getClosureDate(), client.getClosedBy().getUsername(), client.getClosedBy().getFirstname(),
|
||||
client.getClosedBy().getLastname());
|
||||
|
||||
}
|
||||
} else if (client.isActive()) {
|
||||
final AppUser activatedBy = client.getActivatedBy();
|
||||
if (activatedBy != null) {
|
||||
return new ClientTimelineData(client.getSubmittedOnDate(), null, null, null, client.getActivationDate(),
|
||||
activatedBy.getUsername(), activatedBy.getFirstname(), activatedBy.getLastname(),
|
||||
null, null, null, null);
|
||||
}
|
||||
return new ClientTimelineData(client.getSubmittedOnDate(), null, null, null, client.getActivationDate(),
|
||||
null, null, null, null, null, null, null);
|
||||
} else {
|
||||
return new ClientTimelineData(client.getSubmittedOnDate(), null, null, null, null, null, null, null, null, null, null, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Named("clientIsStaff")
|
||||
default Boolean clientIsStaff(Client client) {
|
||||
return Boolean.valueOf(client.isStaff());
|
||||
}
|
||||
|
||||
@Named("guardianClientIdValue")
|
||||
default Long guardianClientIdValue(Client client) {
|
||||
return client.getGuardianClient() != null ? client.getGuardianClient().getId() : null;
|
||||
}
|
||||
|
||||
@Named("guardianClientDisplayNameValue")
|
||||
default String guardianClientDisplayNameValue(Client client) {
|
||||
return client.getGuardianClient() != null ? client.getGuardianClient().getDisplayName() : null;
|
||||
}
|
||||
|
||||
@AfterMapping
|
||||
default void computeAge(Client source, @MappingTarget ClientData target) {
|
||||
final LocalDate dob = source.getDateOfBirth();
|
||||
if (dob != null) {
|
||||
final Period age = Period.between(dob, LocalDate.now());
|
||||
target.setAgeYears(age.getYears());
|
||||
target.setAgeMonths(age.getMonths());
|
||||
target.setAgeDays(age.getDays());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user