var Logic = function(wfItem, dtoPj, superLogic, errors, messageUtil, request, gaService, wfService, wfTaskService, searchBuilderTemplate, log) {
this.wfItem=wfItem;
this.dtoPj=dtoPj;
this.superLogic=superLogic;
this.errors=errors;
this.messageUtil=messageUtil;
this.request=request;
this.gaService=gaService;
this.wfService=wfService;
this.wfTaskService=wfTaskService;
this.searchBuilderTemplate=searchBuilderTemplate;
this.log=log;
this.setInternalOrgUnitList = function() {
var internalOrganizationUnitSet = Packages.it.cilea.core.fragment.util.FragmentUtil.getCurrentFragmentSetByParentAndDiscriminator(wfItem, "it.cilea.wf.model.WfItemElement","internalOrganizationUnit", wfService);
var internalOrganizationUnitSetIterator=internalOrganizationUnitSet.iterator();
while (internalOrganizationUnitSetIterator.hasNext()){
var element = internalOrganizationUnitSetIterator.next();
var orgUnit = element.getOrganizationUnitMap().get("ouId");
var orgUnitRole = element.getWfDictionaryMap().get("roleId");
dtoPj.getDTOUoPjs().add(superLogic.getOrganizationUnit(orgUnit, orgUnitRole, errors));
}
};
this.setFinanciers = function() {
var sendGrantor2Ugov = Packages.it.cilea.core.configuration.util.ConfigurationUtil.getConfigValue("ap.project.grantor.send2ugov.enable");
if (sendGrantor2Ugov && sendGrantor2Ugov.trim().equalsIgnoreCase("true")){
var contractorSet = Packages.it.cilea.core.fragment.util.FragmentUtil.getCurrentFragmentSetByParentAndDiscriminator(wfItem, "it.cilea.wf.model.WfItemElement", "grantor",wfService);
var contractorSetIterator = contractorSet.iterator();
while (contractorSetIterator.hasNext()){
var element = contractorSetIterator.next();
//var organizationUnit = element.getOrganizationUnitMap().get("grantorId");
var enteFinanziatore = superLogic.getEnteFinanziatore(element, this.getFinancing(), contractorSet.size(), errors);
dtoPj.getDTOEfPjs().add(enteFinanziatore);
}
}
};
this.setPartners = function() {
var sendPartner2Ugov = Packages.it.cilea.core.configuration.util.ConfigurationUtil.getConfigValue("ap.project.partner.send2ugov.enable");
if (sendPartner2Ugov && sendPartner2Ugov.trim().equalsIgnoreCase("true")){
var partnerSet = Packages.it.cilea.core.fragment.util.FragmentUtil.getCurrentFragmentSetByParentAndDiscriminator(wfItem, "it.cilea.wf.model.WfItemElement", "partner",wfService);
var partnerSetIterator=partnerSet.iterator();
while (partnerSetIterator.hasNext()){
var element=partnerSetIterator.next();
var organizationUnit = element.getOrganizationUnitMap().get("partnerId");
var partnerRole = element.getWfDictionaryMap().get("partnerRole");
var partecipante = superLogic.getPartecipante(organizationUnit, partnerRole, errors);
dtoPj.getDTOPartPjs().add(partecipante)
}
}
};
this.getContribution = function() {
return wfItem.getNumberMap().get("internalContribution");
};
this.getCofinancing = function() {
return wfItem.getNumberMap().get("internalCofinancing");
};
this.getFinancing = function() {
var coordinatorRoleId = Packages.it.cilea.core.configuration.util.ConfigurationUtil.getConfigValue("ap.project.partner.role.main");
var myOrganization = Packages.it.cilea.core.configuration.util.ConfigurationUtil.getConfigValue("rm.orgunit.external.myOrganization");
var forcedPjInternalCost = Packages.it.cilea.core.configuration.util.ConfigurationUtil.getConfigValue("ap.project.financing.internalCost.send2ugov.forced");
if (forcedPjInternalCost == null)
forcedPjInternalCost = false;
else if (forcedPjInternalCost.equalsIgnoreCase("true")) {
forcedPjInternalCost= forcedPjInternalCost = true;
} else {
forcedPjInternalCost= forcedPjInternalCost = false;
}
if (!forcedPjInternalCost) {
if (coordinatorRoleId == null || myOrganization == null) {
throw "Configuration variables ap.project.partner.role.main and rm.orgunit.external.myOrganization MUST BE DEFINED";
} else {
coordinatorRoleId= coordinatorRoleId = new Packages.java.lang.Integer(coordinatorRoleId);
myOrganization= myOrganization = new Packages.java.lang.Integer(myOrganization);
}
}
var partnerSet = Packages.it.cilea.core.fragment.util.FragmentUtil.getCurrentFragmentSetByParentAndDiscriminator(wfItem, "it.cilea.wf.model.WfItemElement", "partner", wfService);
var partnerSetIterator = partnerSet.iterator();
while (partnerSetIterator.hasNext()) {
var element = partnerSetIterator.next();
var orgUnitRole = element.getWfDictionaryMap().get("partnerRole");
if (orgUnitRole == null) {
errors.reject("error.project.partner.missingRole");
throw "Detected partner without role";
}
var confVal = Packages.it.cilea.wf.util.WfUtil.getParametricConfiguration("ap.<itemType>.partner.main.required", object.getWfItemType());
if (!Packages.org.apache.commons.lang.StringUtils.equalsIgnoreCase("false", confVal)) {
var orgUnit = element.getOrganizationUnitMap().get("partnerId");
if if (myOrganization.equals(orgUnit.getId()) && coordinatorRoleId.equals(orgUnitRole.getId())) {
var globalCost = wfItem.getNumberMap().get("globalCost");
if (globalCost == null)
globalCost= globalCost = Packages.java.math.BigDecimal.ZERO;
var globalContribution = wfItem.getNumberMap().get("globalContribution");
if (globalContribution == null)
globalContribution= globalContribution = Packages.java.math.BigDecimal.ZERO;
var internalCofinancing = wfItem.getNumberMap().get("internalCofinancing");
if (internalCofinancing == null)
var internalCofinancing= internalCofinancing = Packages.java.math.BigDecimal.ZERO;
var manHoursCofinancing = wfItem.getNumberMap().get("internalCofinancingmanHoursCofinancing");
if (internalCofinancingmanHoursCofinancing == null)
internalCofinancing= manHoursCofinancing = Packages.java.math.BigDecimal.ZERO;
return globalCost.subtract(globalCost.subtract(globalContribution).subtract(internalCofinancing).subtract(manHoursCofinancing));
}
}
}
}
}
}
}
return wfItem.getNumberMap().get("internalCost");
};
this.getStartDate = function() {
return wfItem.getDateMap().get("startDate");
};
this.getEndDate = function() {
return wfItem.getDateMap().get("endDate");
};
this.getExpenditureStartDate = function() {
return wfItem.getDateMap().get("expenditureStartDate");
};
this.getExpenditureEndDate = function() {
return wfItem.getDateMap().get("expenditureEndDate");
};
this.getCurrentEndDate = function() {
var extensionSet = Packages.it.cilea.core.fragment.util.FragmentUtil.getCurrentFragmentSetByParentAndDiscriminator(wfItem, "it.cilea.wf.model.WfItemElement", "extension", wfService);
if(extensionSet.isEmpty()){
return null;
} else {
return wfItem.getDateMap().get("endDate");
}
};
this.getIdentifier = function() {
return wfItem.getIdentifier();
};
this.getIdPj = function() {
if(wfItem.getIntegerMap().get("ugovId") != null){
return wfItem.getIntegerMap().get("ugovId");
} else {
return null;
}
};
this.getDescription = function() {
var descriptionAndGrantNumberConcatenationEnabled = Packages.it.cilea.core.configuration.util.ConfigurationUtil.getConfigValue("ap.prj.descriptionAndGrantNumberConcatenationEnabled");
if (descriptionAndGrantNumberConcatenationEnabled && descriptionAndGrantNumberConcatenationEnabled.trim().equalsIgnoreCase("true")){
var stringBuilder = new Packages.java.lang.StringBuilder("");
var descriptionAndGrantNumberConcatenation;
if(wfItem.getStringMap().get("grantNumber") != null){
stringBuilder.append(wfItem.getStringMap().get("grantNumber"));
}
if(wfItem.getDescription() != null){
if(stringBuilder.toString() == "") {
stringBuilder.append(wfItem.getDescription());
} else {
stringBuilder.append('-');
stringBuilder.append(wfItem.getDescription());
}
}
descriptionAndGrantNumberConcatenation = stringBuilder.toString();
if(descriptionAndGrantNumberConcatenation == ""){
return null;
} else {
var length=descriptionAndGrantNumberConcatenation.length();
return descriptionAndGrantNumberConcatenation.substring(0,(length>255)?255:length);
}
} else {
if(wfItem.getDescription() != null){
var length=wfItem.getDescription().length();
return wfItem.getDescription().substring(0,(length>255)?255:length);
} else {
return null;
}
}
};
this.getCup = function() {
var sendCup2Ugov = Packages.it.cilea.core.configuration.util.ConfigurationUtil.getConfigValue("ap.project.cup.send2ugov.enable");
if (sendCup2Ugov && sendCup2Ugov.trim().equalsIgnoreCase("true")){
return wfItem.getStringMap().get("cup");
} else {
return null;
}
};
this.getAcronym = function() {
if(wfItem.getStringMap().get("acronym") != null){
var length = wfItem.getStringMap().get("acronym").length();
return wfItem.getStringMap().get("acronym").substring(0,(length>50)?50:length);
} else {
return null;
}
};
this.getExternalDmsIdentifier = function() {
var externalDmsIdentifierAutogenerated = Packages.it.cilea.core.configuration.util.ConfigurationUtil.getConfigValue("ap.prj.externalDmsIdentifier.autogenerated");
if("true".equals(externalDmsIdentifierAutogenerated)){
return wfItem.getIdentifier();
}else {
return wfItem.getStringMap().get("externalDmsIdentifier");
}
};
this.isSynchronizable = function() {
var legacy = wfItem.getBooleanMap().get("legacy");
var financing = this.getFinancing();
if (Packages.java.lang.Boolean.TRUE.equals(legacy) || financing==null || Packages.java.math.BigDecimal.ZERO.equals(financing))
return Packages.java.lang.Boolean.FALSE;
else
return Packages.java.lang.Boolean.TRUE;
};
this.getResearchNature = function() {
if(wfItem.getWfDictionaryMap().get("researchNature") == null){
return null;
} else {
return wfItem.getWfDictionaryMap().get("researchNature").getStringMap().get("sourceId");
}
};
this.getProjectType = function() {
return superLogic.getProjectType(wfItem);
};
this.getFinanceSchema = function() {
return this.getProjectType();
};
this.getPjInternalCode = function() {
return null;
};
this.getGrantNumber = function() {
if(wfItem.getStringMap().get("grantNumber") == null){
return null;
} else {
return wfItem.getStringMap().get("grantNumber");
}
};
this.getManHoursCofinancing = function() {
return wfItem.getIntegerMapgetNumberMap().get("manHoursCofinancing");
};
this.isContributorStartDateRequired = function() {
var contributorStartDateRequired=Packages.it.cilea.core.configuration.util.ConfigurationUtil.getConfigValue("ap.project.contributor.starDate.required");
if (contributorStartDateRequired){
if (contributorStartDateRequired.trim().equalsIgnoreCase("true")){
return Packages.java.lang.Boolean.TRUE;
} else if (contributorStartDateRequired.trim().equalsIgnoreCase("false")){
return Packages.java.lang.Boolean.FALSE;
} else {
throw "ap.project.contributor.starDate.required MUST BE true or false";
}
} else {
return Packages.java.lang.Boolean.TRUE;
}
};
this.isOwnerStartDateRequired = function() {
var ownerStartDateRequired = Packages.it.cilea.core.configuration.util.ConfigurationUtil.getConfigValue("ap.project.owner.starDate.required");
if (ownerStartDateRequired){
if (ownerStartDateRequired.trim().equalsIgnoreCase("true")){
return Packages.java.lang.Boolean.TRUE;
} else if (ownerStartDateRequired.trim().equalsIgnoreCase("false")){
return Packages.java.lang.Boolean.FALSE;
} else {
throw "ap.project.owner.starDate.required MUST BE true or false";
}
} else {
return Packages.java.lang.Boolean.TRUE;
}
};
};
new Logic(wfItem, dtoPj, superLogic, errors, messageUtil, request, gaService, wfService, wfTaskService, searchBuilderTemplate, log);
|