Search in sources :

Example 1 with BatchInvariant

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

the class EmailGenerationService method generateNewChainEmail.

@Override
public Email generateNewChainEmail(String system, String country, String env, String chain) throws Exception {
    Email email = new Email();
    /* Page Display - START */
    CountryEnvParam myCountryEnvParam;
    myCountryEnvParam = countryEnvParamService.convert(countryEnvParamService.readByKey(system, country, env));
    BatchInvariant myBatchInvariant;
    myBatchInvariant = batchInvariantService.convert(batchInvariantService.readByKey(chain));
    String lastchain = myBatchInvariant.getBatch() + " (" + myBatchInvariant.getDescription() + ")";
    /* Pick the datas from the database */
    String from = parameterService.findParameterByKey("cerberus_smtp_from", system).getValue();
    String host = parameterService.findParameterByKey("cerberus_smtp_host", system).getValue();
    int port = Integer.valueOf(parameterService.findParameterByKey("cerberus_smtp_port", system).getValue());
    String userName = parameterService.findParameterByKey("cerberus_smtp_username", system).getValue();
    String password = parameterService.findParameterByKey("cerberus_smtp_password", system).getValue();
    String to = parameterService.findParameterByKey("cerberus_notification_newchain_to", system).getValue();
    String cc = parameterService.findParameterByKey("cerberus_notification_newchain_cc", system).getValue();
    String subject = parameterService.findParameterByKey("cerberus_notification_newchain_subject", system).getValue();
    String body = parameterService.findParameterByKey("cerberus_notification_newchain_body", system).getValue();
    if (!StringUtil.isNullOrEmptyOrNull(myCountryEnvParam.geteMailBodyChain())) {
        body = myCountryEnvParam.geteMailBodyChain();
    }
    if (!StringUtil.isNullOrEmptyOrNull(myCountryEnvParam.getDistribList())) {
        to = myCountryEnvParam.getDistribList();
    }
    subject = subject.replace("%SYSTEM%", system);
    subject = subject.replace("%COUNTRY%", country);
    subject = subject.replace("%ENV%", env);
    subject = subject.replace("%BUILD%", myCountryEnvParam.getBuild());
    subject = subject.replace("%REVISION%", myCountryEnvParam.getRevision());
    subject = subject.replace("%CHAIN%", lastchain);
    body = body.replace("%SYSTEM%", system);
    body = body.replace("%COUNTRY%", country);
    body = body.replace("%ENV%", env);
    body = body.replace("%BUILD%", myCountryEnvParam.getBuild());
    body = body.replace("%REVISION%", myCountryEnvParam.getRevision());
    body = body.replace("%CHAIN%", lastchain);
    email = emailFactory.create(host, port, userName, password, true, subject, body, from, to, cc);
    return email;
}
Also used : Email(org.cerberus.service.email.entity.Email) CountryEnvParam(org.cerberus.crud.entity.CountryEnvParam) BatchInvariant(org.cerberus.crud.entity.BatchInvariant)

Example 2 with BatchInvariant

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

the class CreateBatchInvariant 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
 * @throws org.cerberus.exception.CerberusException
 * @throws org.json.JSONException
 */
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);
    String charset = request.getCharacterEncoding();
    response.setContentType("application/json");
    // Calling Servlet Transversal Util.
    ServletUtil.servletStart(request);
    /**
     * Parsing and securing all required parameters.
     */
    // Parameter that are already controled by GUI (no need to decode) --> We SECURE them
    // Parameter that needs to be secured --> We SECURE+DECODE them
    String system = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("system"), "", charset);
    String batch = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("batch"), null, charset);
    String description = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("description"), "", charset);
    /**
     * Checking all constrains before calling the services.
     */
    if (StringUtil.isNullOrEmpty(batch)) {
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
        msg.setDescription(msg.getDescription().replace("%ITEM%", "Batch").replace("%OPERATION%", "Create").replace("%REASON%", "Batch name is missing!"));
        ans.setResultMessage(msg);
    } else {
        /**
         * All data seems cleans so we can call the services.
         */
        ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
        IBatchInvariantService batchInvariantService = appContext.getBean(IBatchInvariantService.class);
        IFactoryBatchInvariant factoryBatchInvariant = appContext.getBean(IFactoryBatchInvariant.class);
        BatchInvariant batchData = factoryBatchInvariant.create(system, batch, description);
        ans = batchInvariantService.create(batchData);
        if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
            /**
             * Object created. Adding Log entry.
             */
            ILogEventService logEventService = appContext.getBean(LogEventService.class);
            logEventService.createForPrivateCalls("/CreateBatchInvariant", "CREATE", "Create BatchInvariant : ['" + batch + "']", request);
        }
    }
    /**
     * Formating and returning the json result.
     */
    jsonResponse.put("messageType", ans.getResultMessage().getMessage().getCodeString());
    jsonResponse.put("message", ans.getResultMessage().getDescription());
    response.getWriter().print(jsonResponse);
    response.getWriter().flush();
}
Also used : Answer(org.cerberus.util.answer.Answer) ApplicationContext(org.springframework.context.ApplicationContext) JSONObject(org.json.JSONObject) PolicyFactory(org.owasp.html.PolicyFactory) IFactoryBatchInvariant(org.cerberus.crud.factory.IFactoryBatchInvariant) MessageEvent(org.cerberus.engine.entity.MessageEvent) IBatchInvariantService(org.cerberus.crud.service.IBatchInvariantService) ILogEventService(org.cerberus.crud.service.ILogEventService) IFactoryBatchInvariant(org.cerberus.crud.factory.IFactoryBatchInvariant) BatchInvariant(org.cerberus.crud.entity.BatchInvariant)

Example 3 with BatchInvariant

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

the class ReadBatchInvariant method findBatchInvariantByKey.

private AnswerItem findBatchInvariantByKey(String batch, ApplicationContext appContext, boolean userHasPermissions) throws JSONException, CerberusException {
    AnswerItem item = new AnswerItem();
    JSONObject object = new JSONObject();
    IBatchInvariantService libService = appContext.getBean(IBatchInvariantService.class);
    // finds the project
    AnswerItem answer = null;
    answer = libService.readByKey(batch);
    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
        BatchInvariant bri = (BatchInvariant) answer.getItem();
        JSONObject response = convertToJSONObject(bri);
        object.put("contentTable", response);
    }
    object.put("hasPermissions", userHasPermissions);
    item.setItem(object);
    item.setResultMessage(answer.getResultMessage());
    return item;
}
Also used : JSONObject(org.json.JSONObject) IBatchInvariantService(org.cerberus.crud.service.IBatchInvariantService) AnswerItem(org.cerberus.util.answer.AnswerItem) BatchInvariant(org.cerberus.crud.entity.BatchInvariant)

Example 4 with BatchInvariant

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

the class UpdateBatchInvariant 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);
    String charset = request.getCharacterEncoding();
    response.setContentType("application/json");
    // Calling Servlet Transversal Util.
    ServletUtil.servletStart(request);
    /**
     * Parsing and securing all required parameters.
     */
    // Parameter that are already controled by GUI (no need to decode) --> We SECURE them
    // Parameter that needs to be secured --> We SECURE+DECODE them
    String system = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("system"), "", charset);
    String batch = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("batch"), null, charset);
    String description = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("description"), "", charset);
    /**
     * Checking all constrains before calling the services.
     */
    if (StringUtil.isNullOrEmpty(batch)) {
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
        msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "Update").replace("%REASON%", "Batch is missing!"));
        ans.setResultMessage(msg);
    } else if (StringUtil.isNullOrEmpty(system)) {
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
        msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "Update").replace("%REASON%", "System name is missing!"));
        ans.setResultMessage(msg);
    } else {
        /**
         * All data seems cleans so we can call the services.
         */
        ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
        IBatchInvariantService batchInvariantService = appContext.getBean(IBatchInvariantService.class);
        AnswerItem resp = batchInvariantService.readByKey(batch);
        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%", OBJECT_NAME).replace("%OPERATION%", "Update").replace("%REASON%", "BatchInvariant does not exist."));
            ans.setResultMessage(msg);
        } else {
            /**
             * The service was able to perform the query and confirm the
             * object exist, then we can update it.
             */
            BatchInvariant batchInvariantData = (BatchInvariant) resp.getItem();
            batchInvariantData.setSystem(system);
            batchInvariantData.setDescription(description);
            ans = batchInvariantService.update(batchInvariantData.getBatch(), batchInvariantData);
            if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
                /**
                 * Update was successful. Adding Log entry.
                 */
                ILogEventService logEventService = appContext.getBean(LogEventService.class);
                logEventService.createForPrivateCalls("/UpdateBatchInvariant", "UPDATE", "Updated BatchInvariant : ['" + batch + "']", request);
            }
        }
    }
    /**
     * Formating and returning the json result.
     */
    jsonResponse.put("messageType", ans.getResultMessage().getMessage().getCodeString());
    jsonResponse.put("message", ans.getResultMessage().getDescription());
    response.getWriter().print(jsonResponse);
    response.getWriter().flush();
}
Also used : Answer(org.cerberus.util.answer.Answer) ApplicationContext(org.springframework.context.ApplicationContext) JSONObject(org.json.JSONObject) PolicyFactory(org.owasp.html.PolicyFactory) MessageEvent(org.cerberus.engine.entity.MessageEvent) IBatchInvariantService(org.cerberus.crud.service.IBatchInvariantService) ILogEventService(org.cerberus.crud.service.ILogEventService) LogEventService(org.cerberus.crud.service.impl.LogEventService) ILogEventService(org.cerberus.crud.service.ILogEventService) AnswerItem(org.cerberus.util.answer.AnswerItem) BatchInvariant(org.cerberus.crud.entity.BatchInvariant)

Example 5 with BatchInvariant

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

the class DeleteBatchInvariant 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 batch = policy.sanitize(request.getParameter("batch"));
    /**
     * Checking all constrains before calling the services.
     */
    if (StringUtil.isNullOrEmpty(batch)) {
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
        msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "Delete").replace("%REASON%", "Batch is missing!"));
        ans.setResultMessage(msg);
    } else {
        /**
         * All data seems cleans so we can call the services.
         */
        ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
        IBatchInvariantService batchInvariantService = appContext.getBean(IBatchInvariantService.class);
        AnswerItem resp = batchInvariantService.readByKey(batch);
        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%", OBJECT_NAME).replace("%OPERATION%", "Delete").replace("%REASON%", "Batch 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.
             */
            BatchInvariant batchInvariantData = (BatchInvariant) resp.getItem();
            ans = batchInvariantService.delete(batchInvariantData);
            if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
                /**
                 * Delete was successful. Adding Log entry.
                 */
                ILogEventService logEventService = appContext.getBean(LogEventService.class);
                logEventService.createForPrivateCalls("/DeleteBatchInvariant", "DELETE", "Delete BatchInvariant : ['" + batch + "']", 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 : Answer(org.cerberus.util.answer.Answer) ApplicationContext(org.springframework.context.ApplicationContext) JSONObject(org.json.JSONObject) PolicyFactory(org.owasp.html.PolicyFactory) MessageEvent(org.cerberus.engine.entity.MessageEvent) IBatchInvariantService(org.cerberus.crud.service.IBatchInvariantService) ILogEventService(org.cerberus.crud.service.ILogEventService) AnswerItem(org.cerberus.util.answer.AnswerItem) BatchInvariant(org.cerberus.crud.entity.BatchInvariant)

Aggregations

BatchInvariant (org.cerberus.crud.entity.BatchInvariant)9 IBatchInvariantService (org.cerberus.crud.service.IBatchInvariantService)5 MessageEvent (org.cerberus.engine.entity.MessageEvent)5 AnswerItem (org.cerberus.util.answer.AnswerItem)5 JSONObject (org.json.JSONObject)5 IFactoryBatchInvariant (org.cerberus.crud.factory.IFactoryBatchInvariant)4 ILogEventService (org.cerberus.crud.service.ILogEventService)3 Answer (org.cerberus.util.answer.Answer)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 FactoryBatchInvariant (org.cerberus.crud.factory.impl.FactoryBatchInvariant)2 AnswerList (org.cerberus.util.answer.AnswerList)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1