Search in sources :

Example 6 with BuildRevisionInvariant

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

the class ExecutionCheckService method compareRevision.

private int compareRevision(String rev1, String rev2, String system) {
    try {
        BuildRevisionInvariant r1 = buildRevisionInvariantService.convert(buildRevisionInvariantService.readByKey(system, 2, rev1));
        BuildRevisionInvariant r2 = buildRevisionInvariantService.convert(buildRevisionInvariantService.readByKey(system, 2, rev2));
        return r1.getSeq().compareTo(r2.getSeq());
    } catch (CerberusException e) {
        throw new NumberFormatException();
    }
}
Also used : CerberusException(org.cerberus.exception.CerberusException) BuildRevisionInvariant(org.cerberus.crud.entity.BuildRevisionInvariant)

Example 7 with BuildRevisionInvariant

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

the class DeleteBuildRevisionInvariant 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();
    Answer ans = new Answer();
    MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
    msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
    ans.setResultMessage(msg);
    PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);
    response.setContentType("application/json");
    // Calling Servlet Transversal Util.
    ServletUtil.servletStart(request);
    /**
     * Parsing and securing all required parameters.
     */
    String system = policy.sanitize(request.getParameter("system"));
    Integer level = -1;
    boolean level_error = false;
    try {
        if (request.getParameter("level") != null && !request.getParameter("level").equals("")) {
            level = Integer.valueOf(policy.sanitize(request.getParameter("level")));
        }
    } catch (Exception ex) {
        level_error = true;
    }
    Integer seq = -1;
    boolean seq_error = false;
    try {
        if (request.getParameter("seq") != null && !request.getParameter("seq").equals("")) {
            seq = Integer.valueOf(policy.sanitize(request.getParameter("seq")));
        }
    } catch (Exception ex) {
        seq_error = true;
    }
    /**
     * Checking all constrains before calling the services.
     */
    if (StringUtil.isNullOrEmpty(system)) {
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
        msg.setDescription(msg.getDescription().replace("%ITEM%", "BuildRevisionInvariant").replace("%OPERATION%", "Delete").replace("%REASON%", "System is missing!"));
        ans.setResultMessage(msg);
    } else if (level_error) {
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
        msg.setDescription(msg.getDescription().replace("%ITEM%", "BuildRevisionInvariant").replace("%OPERATION%", "Delete").replace("%REASON%", "Could not manage to convert level to an integer value!"));
        ans.setResultMessage(msg);
    } else if (seq_error) {
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
        msg.setDescription(msg.getDescription().replace("%ITEM%", "BuildRevisionInvariant").replace("%OPERATION%", "Delete").replace("%REASON%", "Could not manage to convert sequence to an integer value!"));
        ans.setResultMessage(msg);
    } else {
        /**
         * All data seems cleans so we can call the services.
         */
        ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
        IBuildRevisionInvariantService buildRevisionInvariantService = appContext.getBean(IBuildRevisionInvariantService.class);
        AnswerItem resp = buildRevisionInvariantService.readByKey(system, level, seq);
        if (!(resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && resp.getItem() != null)) {
            /**
             * Object could not be found. We stop here and report the error.
             */
            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
            msg.setDescription(msg.getDescription().replace("%ITEM%", "BuildRevisionInvariant").replace("%OPERATION%", "Delete").replace("%REASON%", "BuildRevisionInvariant does not exist."));
            ans.setResultMessage(msg);
        } else {
            /**
             * The service was able to perform the query and confirm the
             * object exist, then we can delete it.
             */
            BuildRevisionInvariant buildRevisionInvariantData = (BuildRevisionInvariant) resp.getItem();
            ans = buildRevisionInvariantService.delete(buildRevisionInvariantData);
            if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
                /**
                 * Delete was successful. Adding Log entry.
                 */
                ILogEventService logEventService = appContext.getBean(LogEventService.class);
                logEventService.createForPrivateCalls("/DeleteBuildRevisionInvariant", "DELETE", "Delete BuildRevisionInvariant : ['" + system + "'|'" + level + "'|'" + seq + "']", request);
            }
        }
    }
    /**
     * Formating and returning the json result.
     */
    jsonResponse.put("messageType", ans.getResultMessage().getMessage().getCodeString());
    jsonResponse.put("message", ans.getResultMessage().getDescription());
    response.getWriter().print(jsonResponse.toString());
    response.getWriter().flush();
}
Also used : PolicyFactory(org.owasp.html.PolicyFactory) MessageEvent(org.cerberus.engine.entity.MessageEvent) AnswerItem(org.cerberus.util.answer.AnswerItem) ServletException(javax.servlet.ServletException) JSONException(org.json.JSONException) IOException(java.io.IOException) CerberusException(org.cerberus.exception.CerberusException) IBuildRevisionInvariantService(org.cerberus.crud.service.IBuildRevisionInvariantService) Answer(org.cerberus.util.answer.Answer) ApplicationContext(org.springframework.context.ApplicationContext) JSONObject(org.json.JSONObject) BuildRevisionInvariant(org.cerberus.crud.entity.BuildRevisionInvariant) ILogEventService(org.cerberus.crud.service.ILogEventService)

Example 8 with BuildRevisionInvariant

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

the class ReadBuildRevisionInvariant method findBuildRevisionInvariantList.

// </editor-fold>
private AnswerItem findBuildRevisionInvariantList(String system, Integer level, ApplicationContext appContext, boolean userHasPermissions, HttpServletRequest request) throws JSONException {
    AnswerItem item = new AnswerItem();
    JSONObject object = new JSONObject();
    briService = appContext.getBean(BuildRevisionInvariantService.class);
    int startPosition = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("iDisplayStart"), "0"));
    int length = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("iDisplayLength"), "0"));
    /*int sEcho  = Integer.valueOf(request.getParameter("sEcho"));*/
    String searchParameter = ParameterParserUtil.parseStringParam(request.getParameter("sSearch"), "");
    int columnToSortParameter = Integer.parseInt(ParameterParserUtil.parseStringParam(request.getParameter("iSortCol_0"), "1"));
    String sColumns = ParameterParserUtil.parseStringParam(request.getParameter("sColumns"), "system,level,seq,versionname");
    String[] columnToSort = sColumns.split(",");
    String columnName = columnToSort[columnToSortParameter];
    String sort = ParameterParserUtil.parseStringParam(request.getParameter("sSortDir_0"), "asc");
    List<String> individualLike = new ArrayList(Arrays.asList(ParameterParserUtil.parseStringParam(request.getParameter("sLike"), "").split(",")));
    Map<String, List<String>> individualSearch = new HashMap<String, List<String>>();
    for (int a = 0; a < columnToSort.length; a++) {
        if (null != request.getParameter("sSearch_" + a) && !request.getParameter("sSearch_" + a).isEmpty()) {
            List<String> search = new ArrayList(Arrays.asList(request.getParameter("sSearch_" + a).split(",")));
            if (individualLike.contains(columnToSort[a])) {
                individualSearch.put(columnToSort[a] + ":like", search);
            } else {
                individualSearch.put(columnToSort[a], search);
            }
        }
    }
    AnswerList resp = briService.readBySystemByCriteria(system, level, startPosition, length, columnName, sort, searchParameter, individualSearch);
    JSONArray jsonArray = new JSONArray();
    if (resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
        // the service was able to perform the query, then we should get all values
        for (BuildRevisionInvariant bri : (List<BuildRevisionInvariant>) resp.getDataList()) {
            jsonArray.put(convertBuildRevisionInvariantToJSONObject(bri));
        }
    }
    object.put("hasPermissions", userHasPermissions);
    object.put("contentTable", jsonArray);
    object.put("iTotalRecords", resp.getTotalRows());
    object.put("iTotalDisplayRecords", resp.getTotalRows());
    item.setItem(object);
    item.setResultMessage(resp.getResultMessage());
    return item;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) IBuildRevisionInvariantService(org.cerberus.crud.service.IBuildRevisionInvariantService) BuildRevisionInvariantService(org.cerberus.crud.service.impl.BuildRevisionInvariantService) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) AnswerItem(org.cerberus.util.answer.AnswerItem) JSONObject(org.json.JSONObject) BuildRevisionInvariant(org.cerberus.crud.entity.BuildRevisionInvariant) AnswerList(org.cerberus.util.answer.AnswerList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 9 with BuildRevisionInvariant

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

the class ReadBuildRevisionInvariant method findBuildRevisionInvariantByKey.

private AnswerItem findBuildRevisionInvariantByKey(String system, Integer level, Integer seq, ApplicationContext appContext, boolean userHasPermissions) throws JSONException, CerberusException {
    AnswerItem item = new AnswerItem();
    JSONObject object = new JSONObject();
    IBuildRevisionInvariantService libService = appContext.getBean(IBuildRevisionInvariantService.class);
    // finds the project
    AnswerItem answer = null;
    answer = libService.readByKey(system, level, seq);
    if (answer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
        // if the service returns an OK message then we can get the item and convert it to JSONformat
        BuildRevisionInvariant bri = (BuildRevisionInvariant) answer.getItem();
        JSONObject response = convertBuildRevisionInvariantToJSONObject(bri);
        object.put("contentTable", response);
    }
    object.put("hasPermissions", userHasPermissions);
    item.setItem(object);
    item.setResultMessage(answer.getResultMessage());
    return item;
}
Also used : JSONObject(org.json.JSONObject) BuildRevisionInvariant(org.cerberus.crud.entity.BuildRevisionInvariant) AnswerItem(org.cerberus.util.answer.AnswerItem) IBuildRevisionInvariantService(org.cerberus.crud.service.IBuildRevisionInvariantService)

Example 10 with BuildRevisionInvariant

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

the class ExecutionCheckService method compareBuild.

private int compareBuild(String build1, String build2, String system) throws CerberusException {
    BuildRevisionInvariant b1;
    BuildRevisionInvariant b2;
    try {
        b1 = buildRevisionInvariantService.convert(buildRevisionInvariantService.readByKey(system, 1, build1));
        b2 = buildRevisionInvariantService.convert(buildRevisionInvariantService.readByKey(system, 1, build2));
    } catch (CerberusException e) {
        throw new NumberFormatException();
    }
    if (null == b1 || null == b2) {
        throw new CerberusException(new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_RANGE_ENVIRONMENT_BUILDREVISION_BADLYDEFINED));
    }
    return b1.getSeq().compareTo(b2.getSeq());
}
Also used : CerberusException(org.cerberus.exception.CerberusException) BuildRevisionInvariant(org.cerberus.crud.entity.BuildRevisionInvariant) MessageGeneral(org.cerberus.engine.entity.MessageGeneral)

Aggregations

BuildRevisionInvariant (org.cerberus.crud.entity.BuildRevisionInvariant)10 IBuildRevisionInvariantService (org.cerberus.crud.service.IBuildRevisionInvariantService)5 MessageEvent (org.cerberus.engine.entity.MessageEvent)5 CerberusException (org.cerberus.exception.CerberusException)5 AnswerItem (org.cerberus.util.answer.AnswerItem)5 JSONObject (org.json.JSONObject)5 IFactoryBuildRevisionInvariant (org.cerberus.crud.factory.IFactoryBuildRevisionInvariant)4 IOException (java.io.IOException)3 ServletException (javax.servlet.ServletException)3 ILogEventService (org.cerberus.crud.service.ILogEventService)3 Answer (org.cerberus.util.answer.Answer)3 JSONException (org.json.JSONException)3 PolicyFactory (org.owasp.html.PolicyFactory)3 ApplicationContext (org.springframework.context.ApplicationContext)3 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2