states update

main
Said Gedik 2024-03-19 15:41:18 +01:00
parent c4d929751e
commit 625247e270
3 changed files with 128 additions and 70 deletions

View File

@ -47,7 +47,6 @@ public class RemedyJavaAPI {
server.setPort(46262); server.setPort(46262);
this.connect(); this.connect();
// TODO: move to APIApplication.java or State.java - see where it fits // TODO: move to APIApplication.java or State.java - see where it fits
State.getInstance().queryState(this); State.getInstance().queryState(this);
SupportGroup.getInstance().querySupportGroups(this); SupportGroup.getInstance().querySupportGroups(this);
@ -155,7 +154,6 @@ public class RemedyJavaAPI {
return "Entry deleted successfully. ID: " + entryId; return "Entry deleted successfully. ID: " + entryId;
} }
/** /**
* Takes an entry ID and a {@link Query} object with values and updates the * Takes an entry ID and a {@link Query} object with values and updates the
* selected entry with the values provided in the query. * selected entry with the values provided in the query.
@ -351,6 +349,7 @@ public class RemedyJavaAPI {
} }
} }
public boolean isAdministrator() throws ARException { public boolean isAdministrator() throws ARException {
return server.isAdministrator(); return server.isAdministrator();
} }

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collectors;
import com.bmc.arsys.api.ARException; import com.bmc.arsys.api.ARException;
import com.bmc.arsys.api.Entry; import com.bmc.arsys.api.Entry;
@ -68,7 +69,7 @@ public class State {
* @throws ARException * @throws ARException
*/ */
public void queryState(RemedyJavaAPI api) throws ARException, NotFoundError { public void queryState(RemedyJavaAPI api) throws ARException, NotFoundError {
queryStateNames(api); // queryStateNames(api);
queryPossibleStates(api); queryPossibleStates(api);
if (state.isEmpty()) { if (state.isEmpty()) {
@ -94,45 +95,85 @@ public class State {
.addFieldId("actualState", 700003005) .addFieldId("actualState", 700003005)
.addFieldId("restartFlag", 700003010) .addFieldId("restartFlag", 700003010)
.addFieldId("implementerFlag", 700003012) .addFieldId("implementerFlag", 700003012)
.addFieldId("possibleState", 700003006) // Include possibleState here
.build(); .build();
var stateFields = api.queryFieldsById("\'Menu\' = \"CHANGE_CALENDER_STATUS\"",
configurationQuery.getFieldIds(),
configurationQuery.getFormName(), null, 0, 0);
var configurationStatusQuery = new Query.QueryBuilder("ITSM:Configuration") var configurationStatusQuery = new Query.QueryBuilder("ITSM:Configuration")
.addFieldId("actualState", 700003005) .addFieldId("actualState", 700003005)
.addFieldId("possibleState", 700003006) .addFieldId("possibleState", 700003006)
.build(); .build();
var stateFields = api.queryFieldsById("\'Menu\' = \"CHANGE_CALENDER_STATUS\"",
configurationQuery.getFieldIds(),
configurationQuery.getFormName(), null, 0, 0);
var stateStatusFields = api.queryFieldsById("\'Menu\' = \"CHANGE_CALENDER_STATUS_TRANSITIONS\"", var stateStatusFields = api.queryFieldsById("\'Menu\' = \"CHANGE_CALENDER_STATUS_TRANSITIONS\"",
configurationStatusQuery.getFieldIds(), configurationStatusQuery.getFieldIds(),
configurationStatusQuery.getFormName(), null, 0, 0); configurationStatusQuery.getFormName(), null, 0, 0);
for (int i = 0; i < stateFields.size(); i++) { populateStateInfo(stateFields, stateStatusFields, configurationQuery, configurationStatusQuery);
for (int j = 0; j < stateStatusFields.size(); j++) { // Print state information
printStateInfo();
}
int actualState = stateFields.get(i).get(configurationQuery.getFieldId("actualState")).getIntValue(); private void populateStateInfo(List<Entry> stateFields, List<Entry> stateStatusFields,
int statusActualState = stateStatusFields.get(j).get(configurationStatusQuery.getFieldId("actualState")) Query configurationQuery, Query configurationStatusQuery) throws ARException {
for (var stateField : stateFields) {
int actualState = stateField.get(configurationQuery.getFieldId("actualState")).getIntValue();
boolean cancelFlag = false;
boolean restartFlag = false;
boolean implementerFlag = false;
try {
// Extract additional fields
cancelFlag = stateField.get(configurationQuery.getFieldId("cancelFlag")).toString()
.equals("CANCEL_YES");
restartFlag = stateField.get(configurationQuery.getFieldId("restartFlag")).toString()
.equals("RESTARTALLOWED_YES");
implementerFlag = stateField.get(configurationQuery.getFieldId("implementerFlag")).toString()
.equals("SETIMPLEMENTER_YES");
} catch (Exception e) {
e.printStackTrace();
}
String engName = stateField.get(configurationQuery.getFieldId("engName")).toString();
String gerName = stateField.get(configurationQuery.getFieldId("gerName")).toString();
// Initialize StateInfo with additional fields
StateInfo stateInfo = new StateInfo(engName, gerName, cancelFlag, restartFlag, implementerFlag);
for (var statusField : stateStatusFields) {
int statusActualState = statusField.get(configurationStatusQuery.getFieldId("actualState"))
.getIntValue(); .getIntValue();
if (actualState == statusActualState) { if (actualState == statusActualState) {
int possibleState = stateStatusFields.get(j) int possibleState = statusField.get(configurationStatusQuery.getFieldId("possibleState"))
.get(configurationStatusQuery.getFieldId("possibleState")).getIntValue(); .getIntValue();
this.getState().get(actualState).addPossibleState(possibleState); stateInfo.addPossibleState(possibleState);
} }
} }
// Add StateInfo to the state HashMap
getState().put(actualState, stateInfo);
} }
}
for (var v : get()) { private void printStateInfo() {
System.out.println(v.actualState); for (var state : get()) {
// Join possible states into a single string
String possibleStatesString = String.join(", ",
state.possibleStates.stream().map(Object::toString).collect(Collectors.toList()));
// Print the state information
System.out.printf("\n\n[%s]\n[%s]\n[%s]\n[%s]\n[%b]\n[%b]\n[%b]\n\n",
state.actualState, state.stateNameDE, state.stateNameEN,
possibleStatesString, state.cancelFlag, state.restartFlag, state.implementerFlag);
// Print the number of possible states
System.out.println("Possible States: " + state.possibleStates.size());
} }
System.out.println(stateFields.size());
System.out.println(stateStatusFields.size());
// updatePossibleStates(stateFields, configurationQuery);
} }
/** /**
@ -142,14 +183,16 @@ public class State {
* @param stateFields List of Entry to be processed * @param stateFields List of Entry to be processed
* @param configurationQuery Query object of stateFields * @param configurationQuery Query object of stateFields
*/ */
public void updatePossibleStates(List<Entry> stateFields, Query configurationQuery) { // public void updatePossibleStates(List<Entry> stateFields, Query
stateFields.stream().forEach(entry -> { // configurationQuery) {
var actualState = entry.get(configurationQuery.getFieldId("actualState")).getIntValue(); // stateFields.stream().forEach(entry -> {
var possibleState = entry.get(configurationQuery.getFieldId("possibleState")).getIntValue(); // var actualState =
this.getState().get(actualState).addPossibleState(possibleState); // entry.get(configurationQuery.getFieldId("actualState")).getIntValue();
}); // var possibleState =
} // entry.get(configurationQuery.getFieldId("possibleState")).getIntValue();
// this.getState().get(actualState).addPossibleState(possibleState);
// });
// }
/** /**
* Query the German state name from the specified form. The German name in the * Query the German state name from the specified form. The German name in the
* form is associated with the English one. For merging the names into the * form is associated with the English one. For merging the names into the
@ -159,22 +202,19 @@ public class State {
* @param api Remedy API object * @param api Remedy API object
* @throws ARException if an error occurs during the query * @throws ARException if an error occurs during the query
*/ */
private void queryStateNames(RemedyJavaAPI api) throws ARException { // private void queryStateNames(RemedyJavaAPI api) throws ARException {
var nameQuery = new Query.QueryBuilder("SYS:Menu Items Locale LkUp") // var nameQuery = new Query.QueryBuilder("SYS:Menu Items Locale LkUp")
.addFieldId("englishName", 1000004339) // .addFieldId("englishName", 1000004339)
.addFieldId("germanName", 1000004338) // .addFieldId("germanName", 1000004338)
.addFieldId("Locale", 1000004342) // .addFieldId("Locale", 1000004342)
.addFieldId("SelectionCode", 1000004336) // .addFieldId("SelectionCode", 1000004336)
.build(); // .build();
// var stateNames = api.queryFieldsById("\'Menu Type\' = \"Change Status
var stateNames = api.queryFieldsById("\'Menu Type\' = \"Change Status Values\"", // Values\"",
nameQuery.getFieldIds(), // nameQuery.getFieldIds(),
nameQuery.getFormName(), null, 0, 0); // nameQuery.getFormName(), null, 0, 0);
// updateStateNames(stateNames, nameQuery);
updateStateNames(stateNames, nameQuery); // }
}
/** /**
* Takes the relevant data about state names out of the {@code List<Entry>} and * Takes the relevant data about state names out of the {@code List<Entry>} and
* processes them to be saved into the State. * processes them to be saved into the State.
@ -182,24 +222,24 @@ public class State {
* @param stateFields List of Entry to be processed * @param stateFields List of Entry to be processed
* @param nameQuery Query object of stateFields * @param nameQuery Query object of stateFields
*/ */
public void updateStateNames(List<Entry> stateFields, Query nameQuery) {
stateFields.stream()
.filter(entry -> Optional.ofNullable(entry.get(nameQuery.getFieldId("Locale")))
.map(Object::toString)
.orElse("")
.equals("de"))
.forEach(
entry -> {
var selectionCode = nameQuery.getFieldId("SelectionCode");
var englishName = nameQuery.getFieldId("englishName");
var germanName = nameQuery.getFieldId("germanName");
this.getState().put(entry.get(selectionCode).getIntValue(),
new StateInfo(entry.get(englishName).toString(),
entry.get(germanName).toString()));
});
}
// public void updateStateNames(List<Entry> stateFields, Query nameQuery) {
// stateFields.stream()
// .filter(entry ->
// Optional.ofNullable(entry.get(nameQuery.getFieldId("Locale")))
// .map(Object::toString)
// .orElse("")
// .equals("de"))
// .forEach(
// entry -> {
// var selectionCode = nameQuery.getFieldId("SelectionCode");
// var englishName = nameQuery.getFieldId("englishName");
// var germanName = nameQuery.getFieldId("germanName");
// this.getState().put(entry.get(selectionCode).getIntValue(),
// new StateInfo(entry.get(englishName).toString(),
// entry.get(germanName).toString()));
// });
// }
/** /**
* Generate an Array of JSON objects that consists of all the state information. * Generate an Array of JSON objects that consists of all the state information.
* These are the integer representation of the actual state, an Array of integer * These are the integer representation of the actual state, an Array of integer
@ -209,10 +249,12 @@ public class State {
* @return Array of JSON objects with integer representation of state and * @return Array of JSON objects with integer representation of state and
* {@link StateInfo} * {@link StateInfo}
*/ */
public ArrayList<StateResponse> get() { public ArrayList<StateResponse> get() {
var response = new ArrayList<StateResponse>(); var response = new ArrayList<StateResponse>();
this.state.forEach((key, value) -> { this.state.forEach((key, value) -> {
response.add(new StateResponse(key, value.possibleState, value.stateNameEN, value.stateNameDE)); response.add(new StateResponse(key, value.possibleState, value.stateNameEN, value.stateNameDE,
value.cancelFlag, value.restartFlag, value.implementerFlag));
}); });
return response; return response;
} }
@ -224,6 +266,9 @@ public class State {
String stateNameEN; String stateNameEN;
String stateNameDE; String stateNameDE;
ArrayList<Integer> possibleState; ArrayList<Integer> possibleState;
boolean cancelFlag;
boolean restartFlag;
boolean implementerFlag;
/** /**
* Initializes an instance of the {@link StateInfo} class. * Initializes an instance of the {@link StateInfo} class.
@ -245,10 +290,14 @@ public class State {
* @param stateNameEN state name in English * @param stateNameEN state name in English
* @param stateNameDE state name in German * @param stateNameDE state name in German
*/ */
public StateInfo(String stateNameEN, String stateNameDE) { public StateInfo(String stateNameEN, String stateNameDE, boolean cancelFlag, boolean restartFlag,
this.possibleState = new ArrayList<>(); boolean implementerFlag) {
this.stateNameEN = stateNameEN; this.stateNameEN = stateNameEN;
this.stateNameDE = stateNameDE; this.stateNameDE = stateNameDE;
this.cancelFlag = cancelFlag;
this.restartFlag = restartFlag;
this.implementerFlag = implementerFlag;
this.possibleState = new ArrayList<>();
} }
/** /**
@ -298,6 +347,5 @@ public class State {
public void setStateNameEN(String stateNameEN) { public void setStateNameEN(String stateNameEN) {
this.stateNameEN = stateNameEN; this.stateNameEN = stateNameEN;
} }
} }
} }

View File

@ -10,6 +10,9 @@ public class StateResponse {
public ArrayList<Integer> possibleStates; public ArrayList<Integer> possibleStates;
public String stateNameEN; public String stateNameEN;
public String stateNameDE; public String stateNameDE;
public boolean cancelFlag;
public boolean restartFlag;
public boolean implementerFlag;
/** /**
* Initialize the instance of the JSON response. * Initialize the instance of the JSON response.
@ -20,11 +23,19 @@ public class StateResponse {
* @param stateNameDE state name in german * @param stateNameDE state name in german
*/ */
public StateResponse(int actualState, ArrayList<Integer> possibleState, String stateNameEN, public StateResponse(int actualState, ArrayList<Integer> possibleState, String stateNameEN,
String stateNameDE) { String stateNameDE, boolean cancelFlag, boolean restartFlag, boolean implemeneterFlag) {
this.actualState = actualState; this.actualState = actualState;
this.possibleStates = possibleState; this.possibleStates = possibleState;
this.stateNameEN = stateNameEN; this.stateNameEN = stateNameEN;
this.stateNameDE = stateNameDE; this.stateNameDE = stateNameDE;
this.cancelFlag = cancelFlag;
this.restartFlag = restartFlag;
this.implementerFlag = implemeneterFlag;
}
public Object get(int englishName) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'get'");
} }
} }