startup retrieval error
parent
111ca39b46
commit
cc003d9a6c
|
|
@ -21,6 +21,7 @@ import com.bmc.arsys.api.Timestamp;
|
|||
import com.bmc.arsys.api.Value;
|
||||
import com.nttdata.calender.changes.Change;
|
||||
import com.nttdata.calender.contracts.Contract;
|
||||
import com.nttdata.calender.errorhandling.ErrorTypes.NotFoundError;
|
||||
import com.nttdata.calender.states.State;
|
||||
import com.nttdata.calender.supportgroup.SupportGroup;
|
||||
|
||||
|
|
@ -39,7 +40,7 @@ public class RemedyJavaAPI {
|
|||
/**
|
||||
* Sets up the Remedy API with the server and admin user/password.
|
||||
*/
|
||||
public RemedyJavaAPI() throws ARException {
|
||||
public RemedyJavaAPI() throws ARException, NotFoundError {
|
||||
server = new ARServerUser();
|
||||
server.setServer("itsm-app-dev.asfinag.at");
|
||||
server.setUser("changecalender_integration");
|
||||
|
|
|
|||
|
|
@ -3,12 +3,10 @@ package com.nttdata.calender.contracts;
|
|||
import java.util.ArrayList;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.bmc.arsys.api.ARException;
|
||||
import com.nttdata.calender.api.Query;
|
||||
import com.nttdata.calender.api.RemedyJavaAPI;
|
||||
import com.nttdata.calender.errorhandling.ErrorTypes.NotFoundError;
|
||||
|
||||
/**
|
||||
* Represents a singleton instance of the Contract class, which provides
|
||||
|
|
@ -19,7 +17,6 @@ public class Contract {
|
|||
private static final String formName_changes = "ASF:WI_TAS_Paket";
|
||||
private static final String formName_contracts = "CTR:ContractBase";
|
||||
private static final Contract INSTANCE = new Contract();
|
||||
private static final Logger logger = LogManager.getLogger("logger");
|
||||
private ArrayList<ContractGetResponse> contracts;
|
||||
|
||||
/**
|
||||
|
|
@ -44,47 +41,45 @@ public class Contract {
|
|||
* @param api RemedyJavaAPI object used to connect to the Remedy AR Server
|
||||
*/
|
||||
|
||||
public void queryContracts(RemedyJavaAPI api) {
|
||||
try {
|
||||
ArrayList<ContractGetResponse> allChanges = new ArrayList<ContractGetResponse>();
|
||||
ArrayList<ContractGetResponse> allContracts = new ArrayList<ContractGetResponse>();
|
||||
public void queryContracts(RemedyJavaAPI api) throws ARException, NotFoundError {
|
||||
ArrayList<ContractGetResponse> allChanges = new ArrayList<ContractGetResponse>();
|
||||
ArrayList<ContractGetResponse> allContracts = new ArrayList<ContractGetResponse>();
|
||||
|
||||
var queryChanges = new Query.QueryBuilder(formName_changes)
|
||||
.addFieldId("Contract", 670031002).build();
|
||||
var queryChanges = new Query.QueryBuilder(formName_changes)
|
||||
.addFieldId("Contract", 670031002).build();
|
||||
|
||||
allChanges = api.queryFieldsById("", queryChanges.getFieldIds(), formName_changes, null, 0, 0)
|
||||
.stream()
|
||||
.map(entry -> new ContractGetResponse(null,
|
||||
entry.get(queryChanges.getFieldId("Contract")).toString()))
|
||||
.distinct()
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
allChanges = api.queryFieldsById("", queryChanges.getFieldIds(), formName_changes, null, 0, 0)
|
||||
.stream()
|
||||
.map(entry -> new ContractGetResponse(null,
|
||||
entry.get(queryChanges.getFieldId("Contract")).toString()))
|
||||
.distinct()
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
|
||||
var queryContracts = new Query.QueryBuilder(formName_contracts)
|
||||
.addFieldId("Id", 179)
|
||||
.addFieldId("Name", 8).build();
|
||||
var queryContracts = new Query.QueryBuilder(formName_contracts)
|
||||
.addFieldId("Id", 179)
|
||||
.addFieldId("Name", 8).build();
|
||||
|
||||
allContracts = api
|
||||
.queryFieldsById("\'Contract ID+\' != \"\"", queryContracts.getFieldIds(), formName_contracts, null,
|
||||
0, 0)
|
||||
.stream()
|
||||
.map(entry -> new ContractGetResponse(
|
||||
entry.get(queryContracts.getFieldId("Name")).toString(),
|
||||
entry.get(queryContracts.getFieldId("Id")).toString()))
|
||||
.distinct()
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
allContracts = api
|
||||
.queryFieldsById("\'Contract ID+\' != \"\"", queryContracts.getFieldIds(), formName_contracts, null,
|
||||
0, 0)
|
||||
.stream()
|
||||
.map(entry -> new ContractGetResponse(
|
||||
entry.get(queryContracts.getFieldId("Name")).toString(),
|
||||
entry.get(queryContracts.getFieldId("Id")).toString()))
|
||||
.distinct()
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
|
||||
for (var change : allChanges) {
|
||||
for (var contract : allContracts) {
|
||||
if (change.id.equals(contract.id)) {
|
||||
this.contracts.add(contract);
|
||||
break;
|
||||
}
|
||||
for (var change : allChanges) {
|
||||
for (var contract : allContracts) {
|
||||
if (change.id.equals(contract.id)) {
|
||||
this.contracts.add(contract);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (ARException e) {
|
||||
logger.error("An error occured while querying: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
if (contracts.isEmpty()) {
|
||||
throw new NotFoundError("No contracts found in this context");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,11 +7,13 @@ import java.util.Optional;
|
|||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.web.client.HttpClientErrorException.NotFound;
|
||||
|
||||
import com.bmc.arsys.api.ARException;
|
||||
import com.bmc.arsys.api.Entry;
|
||||
import com.nttdata.calender.api.Query;
|
||||
import com.nttdata.calender.api.RemedyJavaAPI;
|
||||
import com.nttdata.calender.errorhandling.ErrorTypes.NotFoundError;
|
||||
|
||||
/**
|
||||
* The State class is a singleton class responsible for managing and querying
|
||||
|
|
@ -22,7 +24,6 @@ import com.nttdata.calender.api.RemedyJavaAPI;
|
|||
public class State {
|
||||
private HashMap<Integer, StateInfo> state;
|
||||
private static final State INSTANCE = new State();
|
||||
private static final Logger logger = LogManager.getLogger("logger");
|
||||
|
||||
/**
|
||||
* Initializes the state with an empty HashMap.
|
||||
|
|
@ -70,9 +71,13 @@ public class State {
|
|||
* @param api Remedy API object
|
||||
* @throws ARException
|
||||
*/
|
||||
public void queryState(RemedyJavaAPI api) throws ARException {
|
||||
public void queryState(RemedyJavaAPI api) throws ARException, NotFoundError {
|
||||
queryStateNames(api);
|
||||
queryPossibleStates(api);
|
||||
|
||||
if (state.isEmpty()) {
|
||||
throw new NotFoundError("No States found in this context");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import org.apache.logging.log4j.Logger;
|
|||
import com.bmc.arsys.api.ARException;
|
||||
import com.nttdata.calender.api.Query;
|
||||
import com.nttdata.calender.api.RemedyJavaAPI;
|
||||
import com.nttdata.calender.errorhandling.ErrorTypes.NotFoundError;
|
||||
|
||||
/**
|
||||
* The SupportGroup class represents a singleton object that holds information
|
||||
|
|
@ -43,7 +44,7 @@ public class SupportGroup {
|
|||
*
|
||||
* @param api RemedyJavaAPI object used to connect to the Remedy AR Server.
|
||||
*/
|
||||
public void querySupportGroups(RemedyJavaAPI api) throws ARException {
|
||||
public void querySupportGroups(RemedyJavaAPI api) throws ARException, NotFoundError {
|
||||
var querySupportGroups = new Query.QueryBuilder(formName)
|
||||
.addFieldId("SupportGroup", 1000000015)
|
||||
.addFieldId("SupportGroupId", 1)
|
||||
|
|
@ -58,6 +59,10 @@ public class SupportGroup {
|
|||
entry.get(querySupportGroups.getFieldId("SupportGroupId")).toString()))
|
||||
.distinct()
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
|
||||
if (this.supportGroups.isEmpty()) {
|
||||
throw new NotFoundError("No support groups found in this context");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue