Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejs
linenumberstrue
collapsetrue
			var creationByCallEnabled = ConfigurationUtil.getConfigValue("ap.prj.create-by-call.enabled");
			var onlyApprovedCallEnabled = ConfigurationUtil.getConfigValue("ap.prj.create-by-call.only-approved-call.enabled");
			var onlyCallWithGrantorEnabled = ConfigurationUtil.getConfigValue("ap.prj.create-by-call.grantor.required.enabled");
			var isCreationByCall = wfItem.getBooleanMap().get("isCreationByCall");
			if (creationByCallEnabled=="true" && Packages.java.lang.Boolean.TRUE.equals(isCreationByCall)){
				var callId=wfItem.getIntegerMap().get("callId");				
				if (callId==null)				
					errors.rejectValue("integerMap[callId]","error.prj.start.callId.required");					
				else {
					var call=wfService.getWfItem(callId);
					if (call==null)
						errors.rejectValue("integerMap[callId]","error.prj.callId.malformed");
					else {
						if ("true"==onlyApprovedCallEnabled && "approved"!=call.getWfState().getDescription())
							errors.rejectValue("integerMap[callId]","error.prj.callId.notApproved");
						else {
							var projectTypeIdentifier=call.getStringMap().get("linkedProjectType");
							if (projectTypeIdentifier==null)
								errors.rejectValue("integerMap[callId]","error.prj.callId.defaultProjectType.required");
							else {
								var wfItemTypeList=wfService.getWfItemTypeByIdentifier(projectTypeIdentifier, 0);
								if (CollectionUtils.isEmpty(wfItemTypeList) || wfItemTypeList.size()>1)
									errors.rejectValue("integerMap[callId]","error.prj.callId.defaultProjectType.malformed");
							}
							
							var grantorFromCallSet=call.getWfItemElementSet("grantor");
							if ("true"==onlyCallWithGrantorEnabled && (grantorFromCallSet==null || grantorFromCallSet.size()==0))
								errors.rejectValue("integerMap[callId]","error.prj.callId.grantor.required");
						}
					}		
				}
			}
		

...

Code Block
languagejs
linenumberstrue
collapsetrue
		var isCreationByCall=wfItem.getBooleanMap().get("isCreationByCall");
		var creationByCallEnabled = ConfigurationUtil.getConfigValue("ap.prj.create-by-call.enabled");
		
		if (creationByCallEnabled=="true" && Packages.java.lang.Boolean.TRUE.equals(isCreationByCall)){
			var callId=wfItem.getIntegerMap().get("callId");
			
			if (callId!=null) {
				var call=wfService.getWfItem(callId);
				var projectTypeIdentifier=call.getStringMap().get("linkedProjectType");
								
				var wfItemTypeList=wfService.getWfItemTypeByIdentifier(projectTypeIdentifier, 0);
				if (CollectionUtils.isNotEmpty(wfItemTypeList)){
					wfItem.setWfItemTypeId(wfItemType=wfItemTypeList.get(0).getId());					
				}
				
				var callProjectLink = new Packages.it.cilea.wf.model.WfItemLink();
				callProjectLink.setDiscriminator("callProjectLink");
				callProjectLink.setParentId(callId);
				callProjectLink.setChildId(wfItem.getId());
				wfService.saveOrUpdate(callProjectLink);
				wfItem.getParentLinkSet().add(callProjectLink);
				
				var grantorFromCallSet=call.getWfItemElementSet("grantor");
				var grantorFromCallIterator=grantorFromCallSet.iterator();
				while(grantorFromCallIterator.hasNext()){
					var grantorFromCall=grantorFromCallIterator.next();
					
					var grantor = new Packages.it.cilea.wf.model.WfItemElement();
					grantor.setDiscriminator("grantor");
					grantor.setWfItemId(wfItem.getId());				
					grantor.getOrganizationUnitMap().put("grantorId", grantorFromCall.getOrganizationUnitMap().get("grantorId"));
					wfService.saveOrUpdate(grantor);
					wfItem.getWfItemElementSet().add(grantor);
				}
				
				if(call.getBooleanMap().get("pnrr") != null){
					wfItem.getBooleanMap().put("pnrr", call.getBooleanMap().get("pnrr"));
				}
			}
		}
		wfItem.getIntegerMap().put("callId", null);
		wfItem.getBooleanMap().put("isCreationByCall", null);			
		true;
		

...