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;
}
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;
}
Aggregations