Search in sources :

Example 91 with Answer

use of org.cerberus.util.answer.Answer in project cerberus-source by cerberustesting.

the class TagService method createAuto.

@Override
public Answer createAuto(String tagS, String campaign, String user) {
    AnswerItem answerTag;
    answerTag = readByKey(tagS);
    Tag tag = (Tag) answerTag.getItem();
    if (tag == null) {
        Answer ans = tagDAO.create(factoryTag.create(0, tagS, "", campaign, null, user, null, user, null));
        if (!StringUtil.isNullOrEmpty(campaign)) {
            emailService.generateAndSendNotifyStartTagExecution(tagS, campaign);
        }
        return ans;
    // If campaign is not empty, we could notify the Start of campaign execution.
    } else {
        if ((StringUtil.isNullOrEmpty(tag.getCampaign())) && !StringUtil.isNullOrEmpty(campaign)) {
            tag.setCampaign(campaign);
            return tagDAO.update(tag.getTag(), tag);
        }
        return null;
    }
}
Also used : Answer(org.cerberus.util.answer.Answer) Tag(org.cerberus.crud.entity.Tag) IFactoryTag(org.cerberus.crud.factory.IFactoryTag) AnswerItem(org.cerberus.util.answer.AnswerItem)

Example 92 with Answer

use of org.cerberus.util.answer.Answer in project cerberus-source by cerberustesting.

the class AppServiceContentService method compareListAndUpdateInsertDeleteElements.

@Override
public Answer compareListAndUpdateInsertDeleteElements(String service, List<AppServiceContent> newList) {
    Answer ans = new Answer(null);
    MessageEvent msg1 = new MessageEvent(MessageEventEnum.GENERIC_OK);
    Answer finalAnswer = new Answer(msg1);
    List<AppServiceContent> oldList = new ArrayList();
    try {
        oldList = this.convert(this.readByVarious(service, null));
    } catch (CerberusException ex) {
        LOG.error(ex);
    }
    /**
     * Update and Create all objects database Objects from newList
     */
    List<AppServiceContent> listToUpdateOrInsert = new ArrayList(newList);
    listToUpdateOrInsert.removeAll(oldList);
    List<AppServiceContent> listToUpdateOrInsertToIterate = new ArrayList(listToUpdateOrInsert);
    for (AppServiceContent objectDifference : listToUpdateOrInsertToIterate) {
        for (AppServiceContent objectInDatabase : oldList) {
            if (objectDifference.hasSameKey(objectInDatabase)) {
                ans = this.update(objectDifference.getService(), objectDifference.getKey(), objectDifference);
                finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
                listToUpdateOrInsert.remove(objectDifference);
            }
        }
    }
    /**
     * Delete all objects database Objects that do not exist from newList
     */
    List<AppServiceContent> listToDelete = new ArrayList(oldList);
    listToDelete.removeAll(newList);
    List<AppServiceContent> listToDeleteToIterate = new ArrayList(listToDelete);
    for (AppServiceContent tcsDifference : listToDeleteToIterate) {
        for (AppServiceContent 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) AppServiceContent(org.cerberus.crud.entity.AppServiceContent) ArrayList(java.util.ArrayList)

Example 93 with Answer

use of org.cerberus.util.answer.Answer in project cerberus-source by cerberustesting.

the class BuildRevisionParametersService method create.

@Override
public Answer create(BuildRevisionParameters brp) {
    Answer ans = new Answer();
    MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
    msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
    ans.setResultMessage(msg);
    /**
     * Checking if the build Revision has already been deployed. If so the
     * Create cannot be performed
     */
    if (check_buildRevisionAlreadyUsed(brp.getApplication(), brp.getBuild(), brp.getRevision())) {
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
        msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "Create").replace("%REASON%", "Could not create this release as corresponding build " + brp.getBuild() + " revision " + brp.getRevision() + " has already been deployed in an environment."));
        ans.setResultMessage(msg);
        return ans;
    }
    return buildRevisionParametersDAO.create(brp);
}
Also used : Answer(org.cerberus.util.answer.Answer) MessageEvent(org.cerberus.engine.entity.MessageEvent)

Example 94 with Answer

use of org.cerberus.util.answer.Answer in project cerberus-source by cerberustesting.

the class BuildRevisionParametersService method delete.

@Override
public Answer delete(BuildRevisionParameters brp) {
    Answer ans = new Answer();
    MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
    msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
    ans.setResultMessage(msg);
    /**
     * Checking if the build Revision has already been deployed. If so the
     * delete cannot be performed
     */
    if (check_buildRevisionAlreadyUsed(brp.getApplication(), brp.getBuild(), brp.getRevision())) {
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
        msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "Delete").replace("%REASON%", "Could not delete this release as corresponding build " + brp.getBuild() + " revision " + brp.getRevision() + " has already been deployed in an environment."));
        ans.setResultMessage(msg);
        return ans;
    }
    return buildRevisionParametersDAO.delete(brp);
}
Also used : Answer(org.cerberus.util.answer.Answer) MessageEvent(org.cerberus.engine.entity.MessageEvent)

Example 95 with Answer

use of org.cerberus.util.answer.Answer in project cerberus-source by cerberustesting.

the class TestCaseCountryPropertiesService method duplicateList.

@Override
public Answer duplicateList(List<TestCaseCountryProperties> objectList, String targetTest, String targetTestCase) {
    Answer ans = new Answer(null);
    List<TestCaseCountryProperties> listToCreate = new ArrayList();
    for (TestCaseCountryProperties objectToDuplicate : objectList) {
        objectToDuplicate.setTest(targetTest);
        objectToDuplicate.setTestCase(targetTestCase);
        listToCreate.add(objectToDuplicate);
    }
    ans = createList(listToCreate);
    return ans;
}
Also used : Answer(org.cerberus.util.answer.Answer) TestCaseCountryProperties(org.cerberus.crud.entity.TestCaseCountryProperties) ArrayList(java.util.ArrayList)

Aggregations

Answer (org.cerberus.util.answer.Answer)241 MessageEvent (org.cerberus.engine.entity.MessageEvent)227 Connection (java.sql.Connection)127 PreparedStatement (java.sql.PreparedStatement)127 SQLException (java.sql.SQLException)127 ApplicationContext (org.springframework.context.ApplicationContext)77 JSONObject (org.json.JSONObject)75 ILogEventService (org.cerberus.crud.service.ILogEventService)74 PolicyFactory (org.owasp.html.PolicyFactory)60 AnswerItem (org.cerberus.util.answer.AnswerItem)53 CerberusException (org.cerberus.exception.CerberusException)45 ArrayList (java.util.ArrayList)35 JSONException (org.json.JSONException)26 IOException (java.io.IOException)23 ServletException (javax.servlet.ServletException)19 JSONArray (org.json.JSONArray)15 LogEventService (org.cerberus.crud.service.impl.LogEventService)13 TestCase (org.cerberus.crud.entity.TestCase)10 ITestCaseService (org.cerberus.crud.service.ITestCaseService)10 CountryEnvParam (org.cerberus.crud.entity.CountryEnvParam)8