Skip to content

Commit

Permalink
Merge branch 'staging' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
CDGARCIA authored and CDGARCIA committed Jun 13, 2017
2 parents 17b7257 + 2b58020 commit 1ebe3ab
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,7 @@ public String save() {
}

if (deliverable.getResponsiblePartner() != null
&& deliverable.getResponsiblePartner().getProjectPartnerPerson() != null
&& deliverable.getResponsiblePartner().getProjectPartnerPerson().getId() != null
&& deliverable.getResponsiblePartner().getProjectPartnerPerson().getId().longValue() != -1) {
partnerPerson = projectPartnerPersonManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ public ProjectDescriptionAction(APConfig config, ProjectManager projectManager,
this.locationTypeManager = locationManager;
}

/**
* In this method it is checked if there is a draft file and it is eliminated
*/
@Override
public String cancel() {

Expand Down Expand Up @@ -212,6 +215,11 @@ public String getAnualReportURL() {
return config.getDownloadURL() + "/" + this.getAnualReportRelativePath().replace('\\', '/');
}

/**
* The name of the autosave file is constructed and the path is searched
*
* @return Auto save file path
*/
private Path getAutoSaveFilePath() {
String composedClassName = project.getClass().getSimpleName();
String actionFile = this.getActionName().replace("/", "_");
Expand Down Expand Up @@ -383,17 +391,24 @@ public void prepare() throws Exception {
} catch (Exception e) {

}
// SendMailGun s = new SendMailGun();
// s.SendSimple();

/*
* We check that you have a TRANSACTION_ID to know if it is history version
*/
if (this.getRequest().getParameter(APConstants.TRANSACTION_ID) != null) {


transaction = StringUtils.trim(this.getRequest().getParameter(APConstants.TRANSACTION_ID));
/*
* auditLogManager.getHistory Bring us the history with the transaction id
*/
Project history = (Project) auditLogManager.getHistory(transaction);


Map<String, String> specialList = new HashMap<>();
specialList.put(APConstants.PROJECT_FOCUSES_RELATION, "flagshipValue");

/*
* We load the differences of this version with the previous version
*/
this.setDifferences(historyComparator.getDifferences(transaction, specialList, "project"));


Expand Down Expand Up @@ -421,6 +436,9 @@ public void prepare() throws Exception {
}

if (project != null) {
/*
* We validate if there is a draft version
*/
Path path = this.getAutoSaveFilePath();

if (path.toFile().exists() && this.getCurrentUser().isAutoSave()) {
Expand All @@ -435,11 +453,16 @@ public void prepare() throws Exception {
JsonObject jReader = gson.fromJson(reader, JsonObject.class);

AutoSaveReader autoSaveReader = new AutoSaveReader();

/*
* We read the JSON serialized by the front-end and cast it to the object
*/
project = (Project) autoSaveReader.readFromJson(jReader);
Project projectDb = projectManager.getProjectById(project.getId());
project.setProjectEditLeader(projectDb.isProjectEditLeader());
project.setAdministrative(projectDb.getAdministrative());
/*
* We load some BD objects, since the draft only keeps IDs and some data is shown with a different labe
*/
if (project.getClusterActivities() != null) {
for (ProjectClusterActivity projectClusterActivity : project.getClusterActivities()) {
projectClusterActivity.setCrpClusterOfActivity(crpClusterOfActivityManager
Expand Down Expand Up @@ -493,9 +516,15 @@ public void prepare() throws Exception {
project.setFlagships(programs);
project.setRegions(regions);
reader.close();
/*
* We change this variable so that the user knows that he is working on a draft version
*/
this.setDraft(true);
} else {
this.setDraft(false);
/*
* Load the DB information and adjust it to the structures with which the front end
*/
project.setFlagshipValue("");
project.setRegionsValue("");
List<CrpProgram> programs = new ArrayList<>();
Expand Down Expand Up @@ -547,7 +576,9 @@ public void prepare() throws Exception {
project.setScopes(projectLocations);
}
}

/*
* The lists that the front-end needs are loaded
*/
allOwners = new ArrayList<LiaisonUser>();
allOwners.addAll(loggedCrp.getLiasonUsers());
liaisonInstitutions = new ArrayList<LiaisonInstitution>();
Expand Down Expand Up @@ -616,9 +647,16 @@ public void prepare() throws Exception {
projectScales.put(APConstants.PROJECT_SCAPE_REGIONAL, this.getText("project.projectScape.regional"));
projectScales.put(APConstants.PROJECT_SCAPE_GLOBAL, this.getText("project.projectType.global"));


/*
* The base permission is established for the current section
*/
String params[] = {loggedCrp.getAcronym(), project.getId() + ""};
this.setBasePermission(this.getText(Permission.PROJECT_DESCRIPTION_BASE_PERMISSION, params));

/*
* If it is post, the lists are cleaned, this is done because there is a bug of struts, if this is not done it does
* not delete the items deleted by the user
*/
if (this.isHttpPost()) {
if (project.getClusterActivities() != null) {
project.getClusterActivities().clear();
Expand All @@ -640,19 +678,22 @@ public String save() {
if (this.hasPermission("canEdit")) {

Project projectDB = projectManager.getProjectById(project.getId());
/*
* Load basic info project to be saved
*/
project.setActive(true);
project.setCreatedBy(projectDB.getCreatedBy());
project.setModifiedBy(this.getCurrentUser());
project.setModificationJustification("");
project.setActiveSince(projectDB.getActiveSince());
project.setCreateDate(projectDB.getCreateDate());
project.setPresetDate(projectDB.getPresetDate());

/*
* Validations to fill the checkbox fields
*/
if (project.isNoRegional() == null) {
project.setNoRegional(false);
}


if (project.getCrossCuttingCapacity() == null) {
project.setCrossCuttingCapacity(false);
}
Expand Down Expand Up @@ -719,7 +760,9 @@ public String save() {
project.setLiaisonUser(null);
}
}

/*
* Saving the flaghsips and regions
*/
if (project.getFlagshipValue() != null && project.getFlagshipValue().length() > 0) {

for (ProjectFocus projectFocus : projectDB.getProjectFocuses().stream()
Expand Down Expand Up @@ -884,6 +927,9 @@ public String save() {
project.setAnnualReportToDonnor(null);
}
}
/*
* Saving project and add relations we want to save on the history
*/
List<String> relationsName = new ArrayList<>();
relationsName.add(APConstants.PROJECT_FOCUSES_RELATION);
relationsName.add(APConstants.PROJECT_CLUSTER_ACTIVITIES_RELATION);
Expand All @@ -894,12 +940,14 @@ public String save() {
project.setModificationJustification(this.getJustification());
projectManager.saveProject(project, this.getActionName(), relationsName);
Path path = this.getAutoSaveFilePath();

// delete the draft file if exists
if (path.toFile().exists()) {
path.toFile().delete();
}

// check if there is a url to redirect
if (this.getUrl() == null || this.getUrl().isEmpty()) {
// check if there are missing field
Collection<String> messages = this.getActionMessages();
if (!this.getInvalidFields().isEmpty()) {
this.setActionMessages(null);
Expand Down Expand Up @@ -1012,6 +1060,7 @@ public void setTransaction(String transaction) {

@Override
public void validate() {
// if is saving call the validator to check for the missing fields
if (save) {
validator.validate(this, project, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1573,8 +1573,11 @@ private void updateRoles(ProjectPartnerPerson previousPartnerPerson, ProjectPart

role = roleManager.getRoleById(role.getId());
if (!role.getUserRoles().contains(userRole)) {
userRoleManager.saveUserRole(userRole);
this.addCrpUser(partnerPerson.getUser());
if (userRole.getUser() != null) {
userRoleManager.saveUserRole(userRole);
this.addCrpUser(partnerPerson.getUser());
}

}


Expand All @@ -1600,7 +1603,8 @@ private void updateRoles(ProjectPartnerPerson previousPartnerPerson, ProjectPart

// Notifying user that is not the project leader anymore
this.notifyRoleUnassigned(previousPartnerPerson.getUser(), role);
} else if (previousPartnerPerson != null && partnerPerson != null) {
} else if (previousPartnerPerson != null && partnerPerson != null && partnerPerson.getUser() != null
&& partnerPerson.getUser().getId() != null) {
if (!partnerPerson.getUser().getId().equals(previousPartnerPerson.getUser().getId())) {
UserRole userRole = new UserRole();
userRole.setRole(role);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ public void validateOuctome(BaseAction action, CrpProgramOutcome outcome, int i)
}


if (outcome.getSrfTargetUnit().getId().longValue() != -1) {
if (outcome.getSrfTargetUnit() != null && outcome.getSrfTargetUnit().getId() != null
&& outcome.getSrfTargetUnit().getId().longValue() != -1) {
if (outcome.getValue() == null || !this.isValidNumber(outcome.getValue().toString())) {
this.addMessage(action.getText("outcome.action.value.required", params));
action.getInvalidFields().put("input-outcomes[" + i + "].value", InvalidFieldsMessages.EMPTYFIELD);
Expand Down

0 comments on commit 1ebe3ab

Please sign in to comment.