Skip to content

Commit

Permalink
Merge branch 'aiccra-tip-migrations' into aiccra-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjitm committed Mar 20, 2024
2 parents d6f6894 + 6bf7be2 commit 5bea647
Show file tree
Hide file tree
Showing 22 changed files with 383 additions and 324 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,14 @@ public class TipParameters extends MarloBaseEntity implements java.io.Serializab
@Expose
private String tipBaseUrl;
@Expose
private String encryptionKey;
@Expose
private Date tokenDueDate;

public String getEncryptionKey() {
return encryptionKey;
}

@Override
public String getLogDeatil() {
// TODO Auto-generated method stub
Expand Down Expand Up @@ -82,17 +88,21 @@ public Date getTokenDueDate() {
return tokenDueDate;
}


public String getTokenValue() {
return tokenValue;
}


@Override
public boolean isActive() {
// TODO Auto-generated method stub
return false;
}

public void setEncryptionKey(String encryptionKey) {
this.encryptionKey = encryptionKey;
}

@Override
public void setModifiedBy(User modifiedBy) {
// TODO Auto-generated method stub
Expand Down
3 changes: 3 additions & 0 deletions marlo-data/src/main/resources/xmls/TipParameters.hbm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,8 @@
<property name="tipBaseUrl" type="string">
<column name="tip_base_url"/>
</property>
<property name="encryptionKey" type="string">
<column name="encryption_key"/>
</property>
</class>
</hibernate-mapping>
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,26 @@ public class AESConvert {

private static Logger LOG = LoggerFactory.getLogger(AESConvert.class);

public static String stringToAES(String value) {
/**
* @param value String with text to encrypt
* @param encryptionKey String with AES encryption key
* @return String with the encrypt text
*/
public static String stringToAES(String value, String encryptionKey) {
MessageDigest md;
try {
// Generate a secret key
KeyGenerator keygen = KeyGenerator.getInstance("AES");
keygen.init(256); // Use a 256-bit key (AES-256)
SecretKey secretKey = keygen.generateKey();

// Convert the secret key to byte array
byte[] secretKeyBytes = secretKey.getEncoded();
byte[] secretKeyBytes;
if (encryptionKey != null && !encryptionKey.isEmpty()) {
secretKeyBytes = encryptionKey.getBytes();
} else {
// Generate a secret key
KeyGenerator keygen = KeyGenerator.getInstance("AES");
keygen.init(256); // Use a 256-bit key (AES-256)
SecretKey secretKey = keygen.generateKey();

// Convert the secret key to byte array
secretKeyBytes = secretKey.getEncoded();
}

// Convert the text to compress into bytes
String originalText = "Sample text to compress and encrypt using AES";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public String execute() throws Exception {
&& project.getProjecInfoPhase(this.getActualPhase()) != null
&& project.getProjecInfoPhase(this.getActualPhase()).getAdministrative() != null
&& !project.getProjecInfoPhase(this.getActualPhase()).getAdministrative()) {
section.put("missingFields", section.get("missingFields") + "-" + "deliveralbes");
section.put("missingFields", section.get("missingFields") + "-" + "deliverables");
}

Phase phase = this.getActualPhase();
Expand Down Expand Up @@ -332,6 +332,11 @@ public String execute() throws Exception {
}
}

if (deliverable.getDeliverableInfo(phase).getStatus() != null && deliverable.getDeliverableInfo(phase)
.getStatus().intValue() == Integer.parseInt(ProjectStatusEnum.Cancelled.getStatusId())) {
sectionStatus.setMissingFields("");
}

}

if (sectionStatus.getMissingFields().length() > 0) {
Expand Down Expand Up @@ -431,6 +436,12 @@ public String execute() throws Exception {
sectionStatus = new SectionStatus();
sectionStatus.setMissingFields("No section");
}

//
if (this.isAWPBActive()) {
sectionStatus.setMissingFields("");
}

if (sectionStatus.getMissingFields().length() > 0) {
section.put("missingFields", section.get("missingFields") + "-" + sectionStatus.getMissingFields());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ public String createDinamicURL() {
}
}
if (this.hasSpecificities(APConstants.TIP_SECURITY_ACTIVE)) {
tipURL = loginService + "/" + (AESConvert.stringToAES(token + "/staff/" + userEmail));
String encryptionKey = null;
if (tipParameters != null && tipParameters.get(0).getEncryptionKey() != null) {
encryptionKey = tipParameters.get(0).getEncryptionKey();
}
tipURL = loginService + "/" + (AESConvert.stringToAES(token + "/staff/" + userEmail, encryptionKey));
} else {
tipURL = loginService + "/" + token + "/staff/" + userEmail;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,9 +579,11 @@ private MasterReport addi8nParameters(MasterReport masterReport) {
masterReport.getParameterValues().put("i8nDeliverableNewExpectedYear", this.getText("deliverable.newExpectedYear"));
masterReport.getParameterValues().put("i8nDeliverablesActivities", this.getText("project.activities.title"));
masterReport.getParameterValues().put("i8nDeliverablesContributingSHFRM",
this.getText("deliverable.shfrmContribution.question.reporting"));
"Is this deliverable aligned with the Soil Health and Fertility Road Map (SHFRM) implementation?");
masterReport.getParameterValues().put("i8nDeliverablesContributingNarrative",
this.getText("deliverable.shfrmContribution.narrative.reporting"));
"How this deliverable is expecting to contribute to the SHFRM?");
masterReport.getParameterValues().put("i8nDeliverablesContributingNarrativeReporting",
"How this deliverable is contributing to the SHFRM?");
masterReport.getParameterValues().put("i8nDeliverablesActions",
"To which Priority(ies) action is contributing to:");
/*
Expand Down Expand Up @@ -2725,7 +2727,7 @@ private TypedTableModel getDeliverablesReportingTableModel() {
"intellectualAssetDateExpiry", "intellectualAssetAdditionalInformation", "intellectualAssetLinkPublished",
"intellectualAssetCommunication", "otherPartner", "deliv_description", "activities", "geographicScope",
"countries", "regions", "sharedClusters", "focusEvent", "likelyOutcomes", "isContributing",
"contributingNarrative", "shfrmActions"},
"contributingNarrative", "shfrmActions", "contributingNarrativeReporting"},
new Class[] {Long.class, String.class, String.class, String.class, String.class, String.class, String.class,
String.class, String.class, String.class, String.class, String.class, String.class, String.class, String.class,
String.class, String.class, String.class, String.class, String.class, String.class, String.class, String.class,
Expand All @@ -2738,7 +2740,7 @@ private TypedTableModel getDeliverablesReportingTableModel() {
String.class, String.class, String.class, String.class, String.class, String.class, String.class, String.class,
String.class, String.class, String.class, String.class, String.class, String.class, String.class, String.class,
String.class, String.class, String.class, String.class, String.class, String.class, String.class, String.class,
String.class, String.class, String.class, String.class, String.class, String.class},
String.class, String.class, String.class, String.class, String.class, String.class, String.class},
0);
SimpleDateFormat formatter = new SimpleDateFormat("MMM yyyy");
if (!project.getDeliverables().isEmpty()) {
Expand Down Expand Up @@ -3660,7 +3662,7 @@ private TypedTableModel getDeliverablesReportingTableModel() {
}
}

String isContributing = "", contributingNarrative = "", shfrmActions = "";
String isContributing = "", contributingNarrative = "", contributingNarrativeReporting = "", shfrmActions = "";

// SOIL Contribution
if (deliverable.getDeliverableInfo() != null
Expand All @@ -3676,12 +3678,18 @@ private TypedTableModel getDeliverablesReportingTableModel() {

if (isContributing.equals("Yes")) {

if (deliverable.getDeliverableInfo().getShfrmContributionNarrativeAR() != null) {
contributingNarrative = deliverable.getDeliverableInfo().getShfrmContributionNarrativeAR();
if (deliverable.getDeliverableInfo().getShfrmContributionNarrative() != null) {
contributingNarrative = deliverable.getDeliverableInfo().getShfrmContributionNarrative();
} else {
contributingNarrative = "<Not provided>";
}

if (deliverable.getDeliverableInfo().getShfrmContributionNarrativeAR() != null) {
contributingNarrativeReporting = deliverable.getDeliverableInfo().getShfrmContributionNarrativeAR();
} else {
contributingNarrativeReporting = "<Not provided>";
}

List<DeliverableShfrmPriorityAction> actions = new ArrayList<>();
List<DeliverableShfrmSubAction> subActions = new ArrayList<>();
String actionsText = "";
Expand All @@ -3695,7 +3703,7 @@ private TypedTableModel getDeliverablesReportingTableModel() {
if (action != null && action.getShfrmPriorityAction() != null
&& action.getShfrmPriorityAction().getId() != null
&& action.getShfrmPriorityAction().getComposedName() != null) {
actionsText += "<br> " + action.getShfrmPriorityAction().getComposedName();
actionsText += "<br> " + action.getShfrmPriorityAction().getComposedName();
subActions = deliverableShfrmSubActionManager.findByPriorityActionAndPhase(action.getId(),
this.getSelectedPhase().getId());

Expand All @@ -3718,6 +3726,7 @@ private TypedTableModel getDeliverablesReportingTableModel() {
} else {
contributingNarrative = "<Not Apply>";
shfrmActions = "<Not Apply>";
contributingNarrativeReporting = "<Not Apply>";
}

model.addRow(new Object[] {deliverable.getId(), deliverable.getDeliverableInfo().getTitle(), delivType,
Expand All @@ -3737,7 +3746,8 @@ private TypedTableModel getDeliverablesReportingTableModel() {
intellectualAssetPvpBreederCrop, intellectualAssetDateFilling, intellectualAssetDateRegistration,
intellectualAssetDateExpiry, intellectualAssetAdditionalInformation, intellectualAssetLinkPublished,
intellectualAssetCommunication, otherPartner, delivDescription, activities, geographicScope, countries,
regions, sharedClusters, focusEvent, likelyOutcomes, isContributing, contributingNarrative, shfrmActions});
regions, sharedClusters, focusEvent, likelyOutcomes, isContributing, contributingNarrative, shfrmActions,
contributingNarrativeReporting});
}
}
return model;
Expand Down Expand Up @@ -4700,7 +4710,7 @@ private TypedTableModel getDeliverablesTableModel() {
if (action != null && action.getShfrmPriorityAction() != null
&& action.getShfrmPriorityAction().getId() != null
&& action.getShfrmPriorityAction().getComposedName() != null) {
actionsText += "<br> " + action.getShfrmPriorityAction().getComposedName();
actionsText += "<br> " + action.getShfrmPriorityAction().getComposedName();
subActions = deliverableShfrmSubActionManager.findByPriorityActionAndPhase(action.getId(),
this.getSelectedPhase().getId());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ public String save() {
if (tipParameter.getPrivateKey() != null) {
tipParameterSave.setPrivateKey(tipParameter.getPrivateKey());
}
if (tipParameter.getEncryptionKey() != null) {
tipParameterSave.setEncryptionKey(tipParameter.getEncryptionKey());
}

tipParameterManager.saveTipParameters(tipParameterSave);

Expand Down
Loading

0 comments on commit 5bea647

Please sign in to comment.