Search in sources :

Example 11 with CampaignParameter

use of org.cerberus.crud.entity.CampaignParameter in project cerberus-source by cerberustesting.

the class CampaignParameterDAO method findCampaignParameterByKey.

@Override
public CampaignParameter findCampaignParameterByKey(Integer campaignparameterID) throws CerberusException {
    boolean throwEx = false;
    final String query = "SELECT * FROM campaignparameter c WHERE c.campaignparameterID = ?";
    CampaignParameter campaignParameterResult = null;
    try (Connection connection = this.databaseSpring.connect();
        PreparedStatement preStat = connection.prepareStatement(query)) {
        preStat.setInt(1, campaignparameterID);
        try (ResultSet resultSet = preStat.executeQuery()) {
            if (resultSet.first()) {
                campaignParameterResult = this.loadFromResultSet(resultSet);
            }
        } catch (SQLException exception) {
            LOG.warn("Unable to execute query : " + exception.toString());
        }
    } catch (SQLException exception) {
        LOG.warn("Unable to execute query : " + exception.toString());
    }
    if (throwEx) {
        throw new CerberusException(new MessageGeneral(MessageGeneralEnum.NO_DATA_FOUND));
    }
    return campaignParameterResult;
}
Also used : CerberusException(org.cerberus.exception.CerberusException) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) IFactoryCampaignParameter(org.cerberus.crud.factory.IFactoryCampaignParameter) CampaignParameter(org.cerberus.crud.entity.CampaignParameter)

Example 12 with CampaignParameter

use of org.cerberus.crud.entity.CampaignParameter in project cerberus-source by cerberustesting.

the class CampaignParameterService method compareListAndUpdateInsertDeleteElements.

@Override
public Answer compareListAndUpdateInsertDeleteElements(String campaign, List<CampaignParameter> newList) {
    Answer ans = new Answer(null);
    MessageEvent msg1 = new MessageEvent(MessageEventEnum.GENERIC_OK);
    Answer finalAnswer = new Answer(msg1);
    List<CampaignParameter> oldList = new ArrayList();
    try {
        oldList = this.convert(this.readByCampaign(campaign));
    } 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<CampaignParameter> listToUpdateOrInsert = new ArrayList(newList);
    listToUpdateOrInsert.removeAll(oldList);
    List<CampaignParameter> listToUpdateOrInsertToIterate = new ArrayList(listToUpdateOrInsert);
    for (CampaignParameter objectDifference : listToUpdateOrInsertToIterate) {
        for (CampaignParameter 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<CampaignParameter> listToDelete = new ArrayList(oldList);
    listToDelete.removeAll(newList);
    List<CampaignParameter> listToDeleteToIterate = new ArrayList(listToDelete);
    for (CampaignParameter tcsDifference : listToDeleteToIterate) {
        for (CampaignParameter 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) CerberusException(org.cerberus.exception.CerberusException) MessageEvent(org.cerberus.engine.entity.MessageEvent) ArrayList(java.util.ArrayList) CampaignParameter(org.cerberus.crud.entity.CampaignParameter)

Aggregations

CampaignParameter (org.cerberus.crud.entity.CampaignParameter)12 ArrayList (java.util.ArrayList)10 IFactoryCampaignParameter (org.cerberus.crud.factory.IFactoryCampaignParameter)8 Connection (java.sql.Connection)6 PreparedStatement (java.sql.PreparedStatement)6 ResultSet (java.sql.ResultSet)6 SQLException (java.sql.SQLException)6 MessageEvent (org.cerberus.engine.entity.MessageEvent)6 CerberusException (org.cerberus.exception.CerberusException)5 AnswerList (org.cerberus.util.answer.AnswerList)5 ICampaignParameterService (org.cerberus.crud.service.ICampaignParameterService)4 MessageGeneral (org.cerberus.engine.entity.MessageGeneral)4 AnswerItem (org.cerberus.util.answer.AnswerItem)4 JSONArray (org.json.JSONArray)4 JSONObject (org.json.JSONObject)4 List (java.util.List)3 Campaign (org.cerberus.crud.entity.Campaign)3 CampaignLabel (org.cerberus.crud.entity.CampaignLabel)3 ICampaignLabelService (org.cerberus.crud.service.ICampaignLabelService)3 ICampaignService (org.cerberus.crud.service.ICampaignService)3