field values date change

main
Said Gedik 2024-07-05 20:31:52 +02:00
parent e643c6c71a
commit 99907146ad
2 changed files with 58 additions and 29 deletions

View File

@ -288,9 +288,12 @@ public class KalenderRestController {
httpRequest.setAttribute("formName", formName); httpRequest.setAttribute("formName", formName);
change.modifyTimestamp(request); change.modifyTimestamp(request);
httpRequest.setAttribute("listOfFieldValues", change.getListOfFieldValues());
return request; return request;
} }
/** /**
* Updates the state based on the provided {@link StateChangeRequest} object. * Updates the state based on the provided {@link StateChangeRequest} object.
* Returns a response entity with the updated state value. * Returns a response entity with the updated state value.

View File

@ -4,6 +4,7 @@ import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.TimeZone; import java.util.TimeZone;
@ -32,6 +33,7 @@ public class Change {
private Query queryChange; private Query queryChange;
private RemedyJavaAPI api; private RemedyJavaAPI api;
private final static String formName = "ASF:WI_TAS_Paket"; private final static String formName = "ASF:WI_TAS_Paket";
private ArrayList<String> listOfFieldValues;
/** /**
* Constructor for the {@link Change} class which gets autowired with the * Constructor for the {@link Change} class which gets autowired with the
@ -72,6 +74,17 @@ public class Change {
.addFieldId("CurrentStageNumber", 301541700) .addFieldId("CurrentStageNumber", 301541700)
.addFieldId("Plantime", 666000001) .addFieldId("Plantime", 666000001)
.build(); .build();
this.listOfFieldValues = new ArrayList<>();
}
/**
* Returns the list of field values.
*
* @return listOfFieldValues
*/
public List<String> getListOfFieldValues() {
return new ArrayList<>(listOfFieldValues); // Return a copy to ensure immutability
} }
/** /**
@ -138,15 +151,19 @@ public class Change {
change.setChangeNr(getValueStringByID(entry, "ChangeNr")); change.setChangeNr(getValueStringByID(entry, "ChangeNr"));
change.setSupportGroup(getValueStringByID(entry, "SupportGroup")); change.setSupportGroup(getValueStringByID(entry, "SupportGroup"));
change.setStatusReason(getValueStringByID(entry, "StatusReason")); change.setStatusReason(getValueStringByID(entry, "StatusReason"));
if(Optional.ofNullable(getValue(entry, "State")).map(Value::getIntValue).orElse(-1)== 10 || Optional.ofNullable(getValue(entry, "State")).map(Value::getIntValue).orElse(-1)== 9){ if (Optional.ofNullable(getValue(entry, "State")).map(Value::getIntValue).orElse(-1) == 10
if(Optional.ofNullable(getValue(entry, "State")).map(Value::getIntValue).orElse(-1)== 10){ || Optional.ofNullable(getValue(entry, "State")).map(Value::getIntValue)
.orElse(-1) == 9) {
if (Optional.ofNullable(getValue(entry, "State")).map(Value::getIntValue)
.orElse(-1) == 10) {
if (change.getStatusReason().equals("9000")) { if (change.getStatusReason().equals("9000")) {
change.setState(10); change.setState(10);
} else { } else {
change.setState(101); change.setState(101);
} }
} }
if(Optional.ofNullable(getValue(entry, "State")).map(Value::getIntValue).orElse(-1)== 9){ if (Optional.ofNullable(getValue(entry, "State")).map(Value::getIntValue)
.orElse(-1) == 9) {
if (getValueStringByID(entry, "CurrentStageNumber").equals("1")) { if (getValueStringByID(entry, "CurrentStageNumber").equals("1")) {
change.setState(9); change.setState(9);
} else { } else {
@ -246,7 +263,6 @@ public class Change {
return totalHours; return totalHours;
} }
/** /**
* Returns the {@link Value} of an entry based on the provided description. * Returns the {@link Value} of an entry based on the provided description.
* *
@ -302,6 +318,9 @@ public class Change {
* @throws ValidationError * @throws ValidationError
*/ */
public void modifyTimestamp(ChangeUpdateRequest request) throws ARException, ValidationError { public void modifyTimestamp(ChangeUpdateRequest request) throws ARException, ValidationError {
// Clear the list before processing a new request
listOfFieldValues.clear();
String entryId = request.getResourceId(); String entryId = request.getResourceId();
String d2 = request.getD2(); String d2 = request.getD2();
var dateConverter = new DateConverter(); var dateConverter = new DateConverter();
@ -312,10 +331,12 @@ public class Change {
if (state == 0) { if (state == 0) {
Query query = new Query.QueryBuilder("ASF:WI_TAS_Paket") Query query = new Query.QueryBuilder("ASF:WI_TAS_Paket")
.addFieldValue("d2", 1000000350, new Value(ts)).build(); .addFieldValue("d2", 1000000350, new Value(ts)).build();
collectFieldValues(query); // Collect field values
api.modifyEntry(entryId, query); api.modifyEntry(entryId, query);
} else { } else {
Query queryInfrastructureChange = new Query.QueryBuilder("CHG:Infrastructure Change") Query queryInfrastructureChange = new Query.QueryBuilder("CHG:Infrastructure Change")
.addFieldValue("d2", 1000000350, new Value(ts)).build(); .addFieldValue("d2", 1000000350, new Value(ts)).build();
collectFieldValues(queryInfrastructureChange); // Collect field values
var change = api.queryFieldsById("\'Infrastructure Change ID\' = \"" + changeNr + "\"", var change = api.queryFieldsById("\'Infrastructure Change ID\' = \"" + changeNr + "\"",
queryInfrastructureChange.getFieldIds(), queryInfrastructureChange.getFieldIds(),
@ -323,6 +344,11 @@ public class Change {
api.modifyEntry(change.get(0).getEntryId(), queryInfrastructureChange); api.modifyEntry(change.get(0).getEntryId(), queryInfrastructureChange);
} }
}
private void collectFieldValues(Query query) {
for (var entry : query.getFieldValues()) {
listOfFieldValues.add(entry.getFieldId() + ": " + entry.getValue());
}
} }
} }