use of org.cerberus.crud.entity.CountryEnvDeployType in project cerberus-source by cerberustesting.
the class UpdateCountryEnvParam method getCountryEnvironmentDeployTypeFromParameter.
private List<CountryEnvDeployType> getCountryEnvironmentDeployTypeFromParameter(HttpServletRequest request, ApplicationContext appContext, String system, String country, String environment, JSONArray json) throws JSONException {
List<CountryEnvDeployType> cedList = new ArrayList();
IFactoryCountryEnvDeployType cedFactory = appContext.getBean(IFactoryCountryEnvDeployType.class);
for (int i = 0; i < json.length(); i++) {
JSONObject tcsaJson = json.getJSONObject(i);
boolean delete = tcsaJson.getBoolean("toDelete");
String deployType = tcsaJson.getString("deployType");
String jenkinsAgent = tcsaJson.getString("jenkinsAgent");
if (!delete) {
CountryEnvDeployType ced = cedFactory.create(system, country, environment, deployType, jenkinsAgent);
cedList.add(ced);
}
}
return cedList;
}
use of org.cerberus.crud.entity.CountryEnvDeployType in project cerberus-source by cerberustesting.
the class CountryEnvDeployTypeService method compareListAndUpdateInsertDeleteElements.
@Override
public Answer compareListAndUpdateInsertDeleteElements(String system, String country, String environement, List<CountryEnvDeployType> newList) {
Answer ans = new Answer(null);
MessageEvent msg1 = new MessageEvent(MessageEventEnum.GENERIC_OK);
Answer finalAnswer = new Answer(msg1);
List<CountryEnvDeployType> oldList = new ArrayList();
try {
oldList = this.convert(this.readByVarious(system, country, environement, null));
} catch (CerberusException ex) {
LOG.error(ex);
}
/**
* Iterate on (TestCaseStep From Page - TestCaseStep From Database) If
* TestCaseStep in Database has same key : Update and remove from the
* list. If TestCaseStep in database does ot exist : Insert it.
*/
List<CountryEnvDeployType> listToUpdateOrInsert = new ArrayList(newList);
listToUpdateOrInsert.removeAll(oldList);
List<CountryEnvDeployType> listToUpdateOrInsertToIterate = new ArrayList(listToUpdateOrInsert);
for (CountryEnvDeployType objectDifference : listToUpdateOrInsertToIterate) {
for (CountryEnvDeployType objectInDatabase : oldList) {
if (objectDifference.hasSameKey(objectInDatabase)) {
ans = this.update(objectDifference);
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
listToUpdateOrInsert.remove(objectDifference);
}
}
}
/**
* Iterate on (TestCaseStep From Database - TestCaseStep From Page). If
* TestCaseStep in Page has same key : remove from the list. Then delete
* the list of TestCaseStep
*/
List<CountryEnvDeployType> listToDelete = new ArrayList(oldList);
listToDelete.removeAll(newList);
List<CountryEnvDeployType> listToDeleteToIterate = new ArrayList(listToDelete);
for (CountryEnvDeployType tcsDifference : listToDeleteToIterate) {
for (CountryEnvDeployType tcsInPage : newList) {
if (tcsDifference.hasSameKey(tcsInPage)) {
listToDelete.remove(tcsDifference);
}
}
}
if (!listToDelete.isEmpty()) {
ans = this.deleteList(listToDelete);
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
}
// We insert only at the end (after deletion of all potencial enreg - linked with #1281)
if (!listToUpdateOrInsert.isEmpty()) {
ans = this.createList(listToUpdateOrInsert);
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
}
return finalAnswer;
}
Aggregations