Search in sources :

Example 6 with CountryEnvDeployType

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;
}
Also used : CountryEnvDeployType(org.cerberus.crud.entity.CountryEnvDeployType) IFactoryCountryEnvDeployType(org.cerberus.crud.factory.IFactoryCountryEnvDeployType) JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) IFactoryCountryEnvDeployType(org.cerberus.crud.factory.IFactoryCountryEnvDeployType)

Example 7 with CountryEnvDeployType

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;
}
Also used : Answer(org.cerberus.util.answer.Answer) CountryEnvDeployType(org.cerberus.crud.entity.CountryEnvDeployType) CerberusException(org.cerberus.exception.CerberusException) MessageEvent(org.cerberus.engine.entity.MessageEvent) ArrayList(java.util.ArrayList)

Aggregations

CountryEnvDeployType (org.cerberus.crud.entity.CountryEnvDeployType)7 ArrayList (java.util.ArrayList)4 IFactoryCountryEnvDeployType (org.cerberus.crud.factory.IFactoryCountryEnvDeployType)4 JSONObject (org.json.JSONObject)4 ICountryEnvDeployTypeService (org.cerberus.crud.service.ICountryEnvDeployTypeService)3 MessageEvent (org.cerberus.engine.entity.MessageEvent)3 AnswerItem (org.cerberus.util.answer.AnswerItem)3 AnswerList (org.cerberus.util.answer.AnswerList)3 JSONArray (org.json.JSONArray)3 List (java.util.List)2 CerberusException (org.cerberus.exception.CerberusException)2 Answer (org.cerberus.util.answer.Answer)2 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Application (org.cerberus.crud.entity.Application)1 BuildRevisionParameters (org.cerberus.crud.entity.BuildRevisionParameters)1 CountryEnvLink (org.cerberus.crud.entity.CountryEnvLink)1 CountryEnvParam (org.cerberus.crud.entity.CountryEnvParam)1