Search in sources :

Example 6 with CampaignLabel

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

the class UpdateCampaign method processRequest.

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, CerberusException, JSONException {
    JSONObject jsonResponse = new JSONObject();
    ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
    Answer ans = new Answer();
    Answer finalAnswer = new Answer(new MessageEvent(MessageEventEnum.DATA_OPERATION_OK));
    MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
    msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
    ans.setResultMessage(msg);
    response.setContentType("application/json");
    response.setCharacterEncoding("utf8");
    PrintWriter out = response.getWriter();
    String charset = request.getCharacterEncoding();
    // Parameter that are already controled by GUI (no need to decode) --> We SECURE them
    // Parameter that needs to be secured --> We SECURE+DECODE them
    int cID = ParameterParserUtil.parseIntegerParamAndDecode(request.getParameter("CampaignID"), 0, charset);
    String c = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("Campaign"), null, charset);
    String notifystart = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("NotifyStart"), null, charset);
    String notifyend = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("NotifyEnd"), null, charset);
    String desc = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("Description"), null, charset);
    // Parameter that we cannot secure as we need the html --> We DECODE them
    String distriblist = ParameterParserUtil.parseStringParam(request.getParameter("DistribList"), "");
    if (StringUtil.isNullOrEmpty(c)) {
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
        msg.setDescription(msg.getDescription().replace("%ITEM%", "Campaign").replace("%OPERATION%", "Update").replace("%REASON%", "Campaign name is missing!"));
        finalAnswer.setResultMessage(msg);
    } else {
        // Parameter that we cannot secure as we need the html --> We DECODE them
        // String battery = ParameterParserUtil.parseStringParam(request.getParameter("Batteries"), null);
        String parameter = ParameterParserUtil.parseStringParam(request.getParameter("Parameters"), null);
        String label = ParameterParserUtil.parseStringParam(request.getParameter("Labels"), null);
        ICampaignService campaignService = appContext.getBean(ICampaignService.class);
        AnswerItem resp = campaignService.readByKey(c);
        if (!(resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && resp.getItem() != null)) {
            /**
             * Object could not be found. We stop here and report the error.
             */
            finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) resp);
        } else {
            Campaign camp = (Campaign) resp.getItem();
            camp.setDistribList(distriblist);
            camp.setNotifyStartTagExecution(notifystart);
            camp.setNotifyEndTagExecution(notifyend);
            camp.setDescription(desc);
            finalAnswer = campaignService.update(camp);
            if (finalAnswer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
                /**
                 * Adding Log entry.
                 */
                ILogEventService logEventService = appContext.getBean(LogEventService.class);
                logEventService.createForPrivateCalls("/UpdateCampaign", "UPDATE", "Update Campaign : " + c, request);
            }
            if (parameter != null) {
                JSONArray parameters = new JSONArray(parameter);
                ICampaignParameterService campaignParameterService = appContext.getBean(ICampaignParameterService.class);
                IFactoryCampaignParameter factoryCampaignParameter = appContext.getBean(IFactoryCampaignParameter.class);
                ArrayList<CampaignParameter> arr = new ArrayList<>();
                for (int i = 0; i < parameters.length(); i++) {
                    JSONArray bat = parameters.getJSONArray(i);
                    CampaignParameter co = factoryCampaignParameter.create(0, bat.getString(0), bat.getString(2), bat.getString(3));
                    arr.add(co);
                }
                finalAnswer = campaignParameterService.compareListAndUpdateInsertDeleteElements(c, arr);
                if (finalAnswer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
                    /**
                     * Adding Log entry.
                     */
                    ILogEventService logEventService = appContext.getBean(LogEventService.class);
                    logEventService.createForPrivateCalls("/UpdateCampaign", "UPDATE", "Update Campaign Parameter : " + camp.getCampaign(), request);
                }
            }
            if (label != null) {
                JSONArray labels = new JSONArray(label);
                ICampaignLabelService campaignLabelService = appContext.getBean(ICampaignLabelService.class);
                IFactoryCampaignLabel factoryCampaignLabel = appContext.getBean(IFactoryCampaignLabel.class);
                ArrayList<CampaignLabel> arr = new ArrayList<>();
                for (int i = 0; i < labels.length(); i++) {
                    JSONArray bat = labels.getJSONArray(i);
                    CampaignLabel co = factoryCampaignLabel.create(0, bat.getString(0), Integer.valueOf(bat.getString(2)), request.getRemoteUser(), null, request.getRemoteUser(), null);
                    arr.add(co);
                }
                finalAnswer = campaignLabelService.compareListAndUpdateInsertDeleteElements(c, arr);
                if (finalAnswer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
                    /**
                     * Adding Log entry.
                     */
                    ILogEventService logEventService = appContext.getBean(LogEventService.class);
                    logEventService.createForPrivateCalls("/UpdateCampaign", "UPDATE", "Update Campaign Label : " + camp.getCampaign(), request);
                }
            }
        }
    }
    /**
     * Formating and returning the json result.
     */
    jsonResponse.put("messageType", finalAnswer.getResultMessage().getMessage().getCodeString());
    jsonResponse.put("message", finalAnswer.getResultMessage().getDescription());
    response.getWriter().print(jsonResponse);
    response.getWriter().flush();
}
Also used : IFactoryCampaignParameter(org.cerberus.crud.factory.IFactoryCampaignParameter) ICampaignService(org.cerberus.crud.service.ICampaignService) MessageEvent(org.cerberus.engine.entity.MessageEvent) ICampaignParameterService(org.cerberus.crud.service.ICampaignParameterService) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) AnswerItem(org.cerberus.util.answer.AnswerItem) IFactoryCampaignParameter(org.cerberus.crud.factory.IFactoryCampaignParameter) CampaignParameter(org.cerberus.crud.entity.CampaignParameter) Answer(org.cerberus.util.answer.Answer) IFactoryCampaignLabel(org.cerberus.crud.factory.IFactoryCampaignLabel) ApplicationContext(org.springframework.context.ApplicationContext) Campaign(org.cerberus.crud.entity.Campaign) JSONObject(org.json.JSONObject) ILogEventService(org.cerberus.crud.service.ILogEventService) ICampaignLabelService(org.cerberus.crud.service.ICampaignLabelService) IFactoryCampaignLabel(org.cerberus.crud.factory.IFactoryCampaignLabel) CampaignLabel(org.cerberus.crud.entity.CampaignLabel) PrintWriter(java.io.PrintWriter)

Example 7 with CampaignLabel

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

the class ReadCampaign method findCampaignByKey.

private AnswerItem findCampaignByKey(String key, Boolean userHasPermissions, ApplicationContext appContext, HttpServletRequest request) throws JSONException {
    AnswerItem item = new AnswerItem();
    JSONObject object = new JSONObject();
    campaignService = appContext.getBean(ICampaignService.class);
    AnswerItem answer = campaignService.readByKey(key);
    Campaign p;
    if (answer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
        // the service was able to perform the query, then we should get all values
        p = (Campaign) answer.getItem();
        JSONObject response = convertCampaigntoJSONObject(p);
        if (request.getParameter("parameter") != null) {
            ICampaignParameterService campaignParameterService = appContext.getBean(ICampaignParameterService.class);
            AnswerList resp = campaignParameterService.readByCampaign(key);
            if (resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
                // the service was able to perform the query, then we should get all values
                JSONArray a = new JSONArray();
                for (Object c : resp.getDataList()) {
                    CampaignParameter cc = (CampaignParameter) c;
                    a.put(convertCampaignParametertoJSONObject(cc));
                }
                response.put("parameter", a);
            }
        }
        if (request.getParameter("label") != null) {
            ICampaignLabelService campaignLabelService = appContext.getBean(ICampaignLabelService.class);
            AnswerList resp = campaignLabelService.readByVarious(key);
            if (resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
                // the service was able to perform the query, then we should get all values
                JSONArray a = new JSONArray();
                for (Object c : resp.getDataList()) {
                    CampaignLabel cc = (CampaignLabel) c;
                    a.put(convertCampaignLabeltoJSONObject(cc));
                }
                response.put("label", a);
            }
        }
        if (request.getParameter("testcase") != null) {
            ITestCaseService testCaseService = appContext.getBean(ITestCaseService.class);
            String[] campaignList = new String[1];
            campaignList[0] = key;
            AnswerItem<List<TestCase>> resp = testCaseService.findTestCaseByCampaignNameAndCountries(key, null);
            if (resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
                // the service was able to perform the query, then we should get all values
                JSONArray a = new JSONArray();
                for (Object c : resp.getItem()) {
                    TestCase cc = (TestCase) c;
                    a.put(convertTestCasetoJSONObject(cc));
                }
                response.put("testcase", a);
            }
        }
        object.put("contentTable", response);
    }
    object.put("hasPermissions", userHasPermissions);
    item.setItem(object);
    item.setResultMessage(answer.getResultMessage());
    return item;
}
Also used : ICampaignService(org.cerberus.crud.service.ICampaignService) AnswerList(org.cerberus.util.answer.AnswerList) ICampaignParameterService(org.cerberus.crud.service.ICampaignParameterService) JSONArray(org.json.JSONArray) AnswerItem(org.cerberus.util.answer.AnswerItem) CampaignParameter(org.cerberus.crud.entity.CampaignParameter) Campaign(org.cerberus.crud.entity.Campaign) JSONObject(org.json.JSONObject) TestCase(org.cerberus.crud.entity.TestCase) ITestCaseService(org.cerberus.crud.service.ITestCaseService) JSONObject(org.json.JSONObject) ICampaignLabelService(org.cerberus.crud.service.ICampaignLabelService) AnswerList(org.cerberus.util.answer.AnswerList) ArrayList(java.util.ArrayList) List(java.util.List) CampaignLabel(org.cerberus.crud.entity.CampaignLabel)

Example 8 with CampaignLabel

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

the class FactoryCampaignLabel method create.

@Override
public CampaignLabel create(Integer campaignLabelID, String campaign, Integer LabelId, String usrCreated, Timestamp dateCreated, String usrModif, Timestamp dateModif) {
    CampaignLabel newObject = new CampaignLabel();
    newObject.setCampaignLabelID(campaignLabelID);
    newObject.setCampaign(campaign);
    newObject.setLabelId(LabelId);
    newObject.setUsrCreated(usrCreated);
    newObject.setUsrModif(usrModif);
    newObject.setDateCreated(dateCreated);
    newObject.setDateModif(dateModif);
    return newObject;
}
Also used : IFactoryCampaignLabel(org.cerberus.crud.factory.IFactoryCampaignLabel) CampaignLabel(org.cerberus.crud.entity.CampaignLabel)

Example 9 with CampaignLabel

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

the class CampaignLabelDAO method loadFromResultSet.

@Override
public CampaignLabel loadFromResultSet(ResultSet rs) throws SQLException {
    int campaignlabelid = ParameterParserUtil.parseIntegerParam(rs.getString("cpl.campaignlabelid"), 0);
    String campaign = ParameterParserUtil.parseStringParam(rs.getString("cpl.campaign"), "");
    int labelid = ParameterParserUtil.parseIntegerParam(rs.getString("cpl.labelid"), 0);
    String usrModif = ParameterParserUtil.parseStringParam(rs.getString("cpl.UsrModif"), "");
    String usrCreated = ParameterParserUtil.parseStringParam(rs.getString("cpl.UsrCreated"), "");
    Timestamp dateModif = rs.getTimestamp("cpl.DateModif");
    Timestamp dateCreated = rs.getTimestamp("cpl.DateCreated");
    Integer id = ParameterParserUtil.parseIntegerParam(rs.getString("lab.id"), 0);
    String system = ParameterParserUtil.parseStringParam(rs.getString("lab.system"), "");
    String label = ParameterParserUtil.parseStringParam(rs.getString("lab.label"), "");
    String type = ParameterParserUtil.parseStringParam(rs.getString("lab.type"), "");
    String color = ParameterParserUtil.parseStringParam(rs.getString("lab.color"), "");
    String reqType = ParameterParserUtil.parseStringParam(rs.getString("lab.ReqType"), "");
    String reqStatus = ParameterParserUtil.parseStringParam(rs.getString("lab.ReqStatus"), "");
    String reqCriticity = ParameterParserUtil.parseStringParam(rs.getString("lab.ReqCriticity"), "");
    String parentLabel = ParameterParserUtil.parseStringParam(rs.getString("lab.parentLabel"), "");
    String description = ParameterParserUtil.parseStringParam(rs.getString("lab.description"), "");
    String longDesc = ParameterParserUtil.parseStringParam(rs.getString("lab.LongDesc"), "");
    String usrCreated1 = ParameterParserUtil.parseStringParam(rs.getString("lab.usrCreated"), "");
    Timestamp dateCreated1 = rs.getTimestamp("lab.dateCreated");
    String usrModif1 = ParameterParserUtil.parseStringParam(rs.getString("lab.usrModif"), "");
    Timestamp dateModif1 = rs.getTimestamp("lab.dateModif");
    factoryLabel = new FactoryLabel();
    Label labelObj = factoryLabel.create(id, system, label, type, color, parentLabel, reqType, reqStatus, reqCriticity, description, longDesc, usrCreated1, dateCreated1, usrModif1, dateModif1);
    factoryCampaignLabel = new FactoryCampaignLabel();
    CampaignLabel res = factoryCampaignLabel.create(campaignlabelid, campaign, labelid, usrCreated, dateCreated, usrModif, dateModif);
    res.setLabel(labelObj);
    return res;
}
Also used : FactoryLabel(org.cerberus.crud.factory.impl.FactoryLabel) IFactoryLabel(org.cerberus.crud.factory.IFactoryLabel) FactoryCampaignLabel(org.cerberus.crud.factory.impl.FactoryCampaignLabel) Label(org.cerberus.crud.entity.Label) IFactoryCampaignLabel(org.cerberus.crud.factory.IFactoryCampaignLabel) CampaignLabel(org.cerberus.crud.entity.CampaignLabel) FactoryLabel(org.cerberus.crud.factory.impl.FactoryLabel) IFactoryLabel(org.cerberus.crud.factory.IFactoryLabel) FactoryCampaignLabel(org.cerberus.crud.factory.impl.FactoryCampaignLabel) IFactoryCampaignLabel(org.cerberus.crud.factory.IFactoryCampaignLabel) CampaignLabel(org.cerberus.crud.entity.CampaignLabel) Timestamp(java.sql.Timestamp) FactoryCampaignLabel(org.cerberus.crud.factory.impl.FactoryCampaignLabel) IFactoryCampaignLabel(org.cerberus.crud.factory.IFactoryCampaignLabel)

Aggregations

CampaignLabel (org.cerberus.crud.entity.CampaignLabel)9 IFactoryCampaignLabel (org.cerberus.crud.factory.IFactoryCampaignLabel)7 MessageEvent (org.cerberus.engine.entity.MessageEvent)6 ArrayList (java.util.ArrayList)5 FactoryCampaignLabel (org.cerberus.crud.factory.impl.FactoryCampaignLabel)4 AnswerItem (org.cerberus.util.answer.AnswerItem)4 Connection (java.sql.Connection)3 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 SQLException (java.sql.SQLException)3 Campaign (org.cerberus.crud.entity.Campaign)3 CampaignParameter (org.cerberus.crud.entity.CampaignParameter)3 ICampaignLabelService (org.cerberus.crud.service.ICampaignLabelService)3 ICampaignParameterService (org.cerberus.crud.service.ICampaignParameterService)3 ICampaignService (org.cerberus.crud.service.ICampaignService)3 Answer (org.cerberus.util.answer.Answer)3 JSONArray (org.json.JSONArray)3 JSONObject (org.json.JSONObject)3 List (java.util.List)2 IFactoryCampaignParameter (org.cerberus.crud.factory.IFactoryCampaignParameter)2