Search in sources :

Example 11 with Application

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

the class ReadBuildRevisionParameters method findSVNBuildRevisionParametersBySystem.

private AnswerItem findSVNBuildRevisionParametersBySystem(String system, String country, String environment, String build, String revision, String lastbuild, String lastrevision, ApplicationContext appContext, boolean userHasPermissions) throws JSONException {
    AnswerItem item = new AnswerItem();
    JSONObject object = new JSONObject();
    brpService = appContext.getBean(IBuildRevisionParametersService.class);
    appService = appContext.getBean(IApplicationService.class);
    cedtService = appContext.getBean(ICountryEnvDeployTypeService.class);
    if (StringUtil.isNullOrEmpty(lastbuild)) {
        lastbuild = build;
    }
    AnswerList resp = brpService.readMaxSVNReleasePerApplication(system, build, revision, lastbuild, lastrevision);
    JSONArray jsonArray = new JSONArray();
    JSONObject newSubObj = new JSONObject();
    if (resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
        // the service was able to perform the query, then we should get all values
        for (BuildRevisionParameters brp : (List<BuildRevisionParameters>) resp.getDataList()) {
            newSubObj = convertBuildRevisionParametersToJSONObject(brp);
            // We get here the links of all corresponding deployTypes.
            Application app;
            try {
                app = appService.convert(appService.readByKey(brp.getApplication()));
                for (CountryEnvDeployType JenkinsAgent : cedtService.convert(cedtService.readByVarious(system, country, environment, app.getDeploytype()))) {
                    String DeployURL = "JenkinsDeploy?application=" + brp.getApplication() + "&jenkinsagent=" + JenkinsAgent.getJenkinsAgent() + "&country=" + country + "&deploytype=" + app.getDeploytype() + "&release=" + brp.getRelease() + "&jenkinsbuildid=" + brp.getJenkinsBuildId() + "&repositoryurl=" + brp.getRepositoryUrl();
                    JSONObject newSubObjContent = new JSONObject();
                    newSubObjContent.put("jenkinsAgent", JenkinsAgent.getJenkinsAgent());
                    newSubObjContent.put("link", DeployURL);
                    newSubObj.append("install", newSubObjContent);
                }
            } catch (CerberusException ex) {
                LOG.warn(ex);
            }
            jsonArray.put(newSubObj);
        }
    }
    object.put("contentTable", jsonArray);
    object.put("iTotalRecords", resp.getTotalRows());
    object.put("iTotalDisplayRecords", resp.getTotalRows());
    object.put("hasPermissions", userHasPermissions);
    item.setItem(object);
    item.setResultMessage(resp.getResultMessage());
    return item;
}
Also used : CountryEnvDeployType(org.cerberus.crud.entity.CountryEnvDeployType) AnswerList(org.cerberus.util.answer.AnswerList) CerberusException(org.cerberus.exception.CerberusException) JSONArray(org.json.JSONArray) IBuildRevisionParametersService(org.cerberus.crud.service.IBuildRevisionParametersService) ICountryEnvDeployTypeService(org.cerberus.crud.service.ICountryEnvDeployTypeService) AnswerItem(org.cerberus.util.answer.AnswerItem) JSONObject(org.json.JSONObject) BuildRevisionParameters(org.cerberus.crud.entity.BuildRevisionParameters) AnswerList(org.cerberus.util.answer.AnswerList) ArrayList(java.util.ArrayList) List(java.util.List) Application(org.cerberus.crud.entity.Application) IApplicationService(org.cerberus.crud.service.IApplicationService)

Example 12 with Application

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

the class EmailBodyGeneration method GenerateBuildContentTable.

@Override
public String GenerateBuildContentTable(String system, String build, String revision, String lastBuild, String lastRevision) {
    String buildContentTemplate = "";
    String buildContentTable = "";
    try (Connection conn = databaseSpring.connect();
        Statement stmtBuildContent = conn.createStatement()) {
        String bugURL = "";
        List<Application> appliList = applicationService.convert(applicationService.readBySystem(system));
        buildContentTable = "Here are the last modifications since last change (" + lastBuild + "/" + lastRevision + ") :";
        buildContentTable = buildContentTable + "<table>";
        buildContentTable = buildContentTable + "<thead><tr style=\"background-color:#cad3f1; font-style:bold\"><td>" + "Sprint/Rev</td><td>Application</td><td>Project</td><td>Bug</td><td>Ticket</td><td>People in Charge</td><td>Release Documentation</td></tr></thead><tbody>";
        StringBuilder contentSQLSB = new StringBuilder("SELECT b.`Build`, b.`Revision`, b.`Release` , b.`Link` , ").append(" b.`Application`, b.`ReleaseOwner`, b.`BugIDFixed`, b.`TicketIDFixed`, b.`subject`, b.`Project`").append(", p.`VCCode`, u.Name, a.BugTrackerUrl ").append(" from buildrevisionparameters b ").append(" left outer join project p on p.idproject=b.project ").append(" left outer join user u on u.Login=b.ReleaseOwner ").append(" left outer join application a on a.application=b.application ").append(" join buildrevisioninvariant bri on bri.versionname = b.revision and bri.`system` = '").append(system).append("'  and bri.`level` = 2 ").append(" where build = '").append(build).append("' and a.system = '").append(system).append("' ");
        if (!StringUtil.isNullOrEmpty(lastRevision)) {
            // If lasRevision not defined, we take everything.
            contentSQLSB.append(" and bri.seq > (select seq from buildrevisioninvariant where `system` = '").append(system).append("' and `level` = 2 and `versionname` = '").append(lastRevision).append("' )  ");
        }
        contentSQLSB.append(" and bri.seq <= (select seq from buildrevisioninvariant where `system` = '").append(system).append("' and `level` = 2 and `versionname` = '").append(revision).append("' )  ").append(" order by b.Build, bri.seq, b.Application, b.datecre,").append(" b.TicketIDFixed, b.BugIDFixed, b.`Release`").toString();
        String contentSQL = contentSQLSB.toString();
        LOG.debug(Infos.getInstance().getProjectNameAndVersion() + " - SQL : " + contentSQL);
        try (ResultSet rsBC = stmtBuildContent.executeQuery(contentSQL)) {
            if (rsBC.first()) {
                String bckColor = "#f3f6fa";
                int a = 1;
                do {
                    a++;
                    int b;
                    b = a % 2;
                    if (b == 1) {
                        bckColor = "#e1e7f3";
                    } else {
                        bckColor = "White";
                    }
                    String contentBugURL = "";
                    String contentBuild = "";
                    String contentAppli = "";
                    String contentRev = "";
                    String subject = "";
                    String release = "";
                    String releaseOwner = "";
                    String BugIDFixed = " ";
                    String TicketIDFixed = " ";
                    String Project = " ";
                    String ProjectVC = " ";
                    if (rsBC.getString("a.BugTrackerUrl") != null) {
                        contentBugURL = rsBC.getString("a.BugTrackerUrl");
                    }
                    if (rsBC.getString("b.build") != null) {
                        contentBuild = rsBC.getString("b.build");
                    }
                    if (rsBC.getString("b.Application") != null) {
                        contentAppli = rsBC.getString("b.Application");
                    }
                    if (rsBC.getString("b.Revision") != null) {
                        contentRev = rsBC.getString("b.Revision");
                    }
                    if (rsBC.getString("subject") != null) {
                        subject = rsBC.getString("subject");
                    }
                    if (rsBC.getString("Release") != null) {
                        release = rsBC.getString("Release");
                    }
                    if (rsBC.getString("Name") != null) {
                        releaseOwner = rsBC.getString("Name");
                    } else {
                        releaseOwner = rsBC.getString("ReleaseOwner");
                    }
                    if (!StringUtil.isNullOrEmpty(rsBC.getString("Link"))) {
                        release = "<a target=\"_blank\" href=\"" + rsBC.getString("Link") + "\">" + release + "</a>";
                    }
                    if (rsBC.getString("BugIDFixed") != null) {
                        BugIDFixed = rsBC.getString("BugIDFixed");
                    }
                    if (rsBC.getString("TicketIDFixed") != null) {
                        TicketIDFixed = rsBC.getString("TicketIDFixed");
                    }
                    if (rsBC.getString("Project") != null) {
                        Project = rsBC.getString("Project");
                    }
                    if (!StringUtil.isNullOrEmpty(rsBC.getString("p.VCCode"))) {
                        ProjectVC = Project + " (" + rsBC.getString("p.VCCode") + ")";
                    } else {
                        ProjectVC = Project;
                    }
                    buildContentTable = buildContentTable + "<tr style=\"background-color:" + bckColor + "; font-size:80%\">" + "<td  rowspan=\"2\">" + contentBuild + "/" + contentRev + "</td>" + "<td>" + contentAppli + "</td>" + "<td>" + ProjectVC + "</td>";
                    if (StringUtil.isNullOrEmpty(contentBugURL)) {
                        buildContentTable = buildContentTable + "<td>" + BugIDFixed + "</td>";
                    } else {
                        buildContentTable = buildContentTable + "<td><a target=\"_blank\" href=\"" + contentBugURL.replace("%BUGID%", BugIDFixed) + "\">" + BugIDFixed + "</a></td>";
                    }
                    buildContentTable = buildContentTable + "<td>" + TicketIDFixed + "</td>" + "<td>" + releaseOwner + "</td>" + "<td>" + release + "</td>" + "</tr>" + "<tr style=\"background-color:" + bckColor + "; font-size:80%\">" + "<td colspan=\"6\">" + subject + "</td>" + "</tr>";
                } while (rsBC.next());
            }
            buildContentTable = buildContentTable + "</tbody></table><br>";
            buildContentTemplate = buildContentTable;
        } catch (Exception e) {
            LOG.warn(Infos.getInstance().getProjectNameAndVersion() + " - Exception catched.", e);
        }
    } catch (Exception e) {
        LOG.warn(Infos.getInstance().getProjectNameAndVersion() + " - Exception catched.", e);
    }
    return buildContentTemplate;
}
Also used : Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) Application(org.cerberus.crud.entity.Application)

Example 13 with Application

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

the class CreateTestCaseLabel 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());
    ILogEventService logEventService = appContext.getBean(LogEventService.class);
    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
    // Parameter that we cannot secure as we need the html --> We DECODE them
    Integer myIdInt = 0;
    String[] myLabelIdList = request.getParameterValues("labelid");
    String[] myTestList = request.getParameterValues("test");
    String[] myTestCaseList = request.getParameterValues("testcase");
    if ((myTestList.length == 0) || (myTestCaseList.length == 0) || (myLabelIdList.length == 0)) {
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
        msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "Create").replace("%REASON%", "Missing Parameter (either test, testcase or labelid)."));
        ans.setResultMessage(msg);
    } else if (myTestList.length != myTestCaseList.length) {
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
        msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "Create").replace("%REASON%", "Number of Test does not match number of testcase."));
        ans.setResultMessage(msg);
    }
    StringBuilder output_message = new StringBuilder();
    int massErrorCounter = 0;
    for (int i = 0; i < myLabelIdList.length; i++) {
        String myLabelId = myLabelIdList[i];
        myIdInt = 0;
        boolean label_error = true;
        try {
            if (myLabelId != null && !myLabelId.equals("")) {
                myIdInt = Integer.valueOf(policy.sanitize(myLabelId));
                label_error = false;
            }
        } catch (Exception ex) {
            label_error = true;
        }
        /**
         * Checking all constrains before calling the services.
         */
        if (label_error) {
            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
            msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "Update").replace("%REASON%", "Could not manage to convert labelid to an integer value or labelid is missing."));
            ans.setResultMessage(msg);
            massErrorCounter++;
            output_message.append("<br>id : ").append(myLabelId).append(" - ").append(msg.getDescription());
        } else {
            /**
             * All data seems cleans so we can call the services.
             */
            ILabelService labelService = appContext.getBean(ILabelService.class);
            IFactoryTestCaseLabel factoryTestCaseLabel = appContext.getBean(IFactoryTestCaseLabel.class);
            ITestCaseLabelService testCaseLabelService = appContext.getBean(ITestCaseLabelService.class);
            ITestCaseService testCaseService = appContext.getBean(ITestCaseService.class);
            IApplicationService applicationService = appContext.getBean(IApplicationService.class);
            AnswerItem resp = labelService.readByKey(myIdInt);
            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%", "Create").replace("%REASON%", "Label does not exist."));
                ans.setResultMessage(msg);
                massErrorCounter++;
                output_message.append("<br>labelid : ").append(myLabelId).append(" - ").append(msg.getDescription());
            } else {
                Label myLab = (Label) resp.getItem();
                for (int j = 0; j < myTestList.length; j++) {
                    String myTest = myTestList[j];
                    String myTestCase = myTestCaseList[j];
                    resp = testCaseService.readByKey(myTest, myTestCase);
                    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%", "Create").replace("%REASON%", "Test Case does not exist."));
                        ans.setResultMessage(msg);
                        massErrorCounter++;
                        output_message.append("<br>testcase : ").append(myLabelId).append(" - ").append(msg.getDescription());
                    } else {
                        TestCase myTestCaseObj = (TestCase) resp.getItem();
                        resp = applicationService.readByKey(myTestCaseObj.getApplication());
                        if ((resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && resp.getItem() != null)) {
                            Application myApplication = (Application) resp.getItem();
                            if ((StringUtil.isNullOrEmpty(myLab.getSystem())) || (myApplication.getSystem().equals(myLab.getSystem()))) {
                                TestCaseLabel tcLabel = factoryTestCaseLabel.create(0, myTest, myTestCase, myIdInt, request.getRemoteUser(), null, "", null, null);
                                ans = testCaseLabelService.create(tcLabel);
                                if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
                                    /**
                                     * Update was successful. Adding Log
                                     * entry.
                                     */
                                    logEventService.createForPrivateCalls("/CreateTestCaseLabel", "CREATE", "Created TestCaseLabel : ['" + myIdInt + "'|'" + myTest + "'|'" + myTestCase + "']", request);
                                } else {
                                    massErrorCounter++;
                                    output_message.append("<br>Label : ").append(myLabelId).append(" Test : '").append(myTest).append("' TestCase : '").append(myTestCase).append("' - ").append(ans.getResultMessage().getDescription());
                                }
                            } else {
                                massErrorCounter++;
                                output_message.append("<br>Label : ").append(myLabelId).append(" Test : '").append(myTest).append("' TestCase : '").append(myTestCase).append("' - ").append("Label does not belong to the same system as TestCase system.");
                            }
                        }
                    }
                }
            }
        }
    }
    if (myTestList.length > 1) {
        if (massErrorCounter == myTestList.length) {
            // All updates are in ERROR.
            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
            msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "Mass Update").replace("%REASON%", massErrorCounter + " label links(s) out of " + (myTestList.length * myLabelIdList.length) + " failed to be created due to an issue.<br>") + output_message.toString());
            ans.setResultMessage(msg);
        } else if (massErrorCounter > 0) {
            // At least 1 update in error
            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING);
            msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "Mass Update").replace("%REASON%", massErrorCounter + " label links(s) out of " + (myTestList.length * myLabelIdList.length) + " failed to be created due to an issue.<br>") + output_message.toString());
            ans.setResultMessage(msg);
        } else {
            // No error detected.
            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
            msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "Mass Update") + "\n\nAll " + (myTestList.length * myLabelIdList.length) + " label links(s) created successfuly.");
            ans.setResultMessage(msg);
        }
        logEventService.createForPrivateCalls("/CreateTestCaseLabel", "MASSUPDATE", msg.getDescription(), 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 : PolicyFactory(org.owasp.html.PolicyFactory) MessageEvent(org.cerberus.engine.entity.MessageEvent) TestCaseLabel(org.cerberus.crud.entity.TestCaseLabel) IFactoryTestCaseLabel(org.cerberus.crud.factory.IFactoryTestCaseLabel) TestCaseLabel(org.cerberus.crud.entity.TestCaseLabel) Label(org.cerberus.crud.entity.Label) IFactoryTestCaseLabel(org.cerberus.crud.factory.IFactoryTestCaseLabel) AnswerItem(org.cerberus.util.answer.AnswerItem) ServletException(javax.servlet.ServletException) JSONException(org.json.JSONException) IOException(java.io.IOException) CerberusException(org.cerberus.exception.CerberusException) ILabelService(org.cerberus.crud.service.ILabelService) Answer(org.cerberus.util.answer.Answer) ApplicationContext(org.springframework.context.ApplicationContext) JSONObject(org.json.JSONObject) TestCase(org.cerberus.crud.entity.TestCase) ITestCaseService(org.cerberus.crud.service.ITestCaseService) ILogEventService(org.cerberus.crud.service.ILogEventService) Application(org.cerberus.crud.entity.Application) IFactoryTestCaseLabel(org.cerberus.crud.factory.IFactoryTestCaseLabel) ITestCaseLabelService(org.cerberus.crud.service.ITestCaseLabelService) IApplicationService(org.cerberus.crud.service.IApplicationService)

Example 14 with Application

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

the class FactoryApplication method create.

@Override
public Application create(String application) {
    Application newObject = new Application();
    newObject.setApplication(application);
    return newObject;
}
Also used : Application(org.cerberus.crud.entity.Application) IFactoryApplication(org.cerberus.crud.factory.IFactoryApplication)

Example 15 with Application

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

the class FactoryApplication method create.

@Override
public Application create(String application, String description, int sort, String type, String system, String subsystem, String svnurl, String deploytype, String mavengroupid, String bugTrackerUrl, String bugTrackerNewUrl, String usrCreated, Timestamp dateCreated, String usrModif, Timestamp dateModif) {
    Application newObject = new Application();
    newObject.setApplication(application);
    newObject.setDeploytype(deploytype);
    newObject.setDescription(description);
    newObject.setMavengroupid(mavengroupid);
    newObject.setSort(sort);
    newObject.setSubsystem(subsystem);
    newObject.setSvnurl(svnurl);
    newObject.setSystem(system);
    newObject.setType(type);
    newObject.setBugTrackerUrl(bugTrackerUrl);
    newObject.setBugTrackerNewUrl(bugTrackerNewUrl);
    newObject.setUsrModif(usrModif);
    newObject.setUsrCreated(usrCreated);
    newObject.setDateModif(dateModif);
    newObject.setDateCreated(dateCreated);
    return newObject;
}
Also used : Application(org.cerberus.crud.entity.Application) IFactoryApplication(org.cerberus.crud.factory.IFactoryApplication)

Aggregations

Application (org.cerberus.crud.entity.Application)18 IApplicationService (org.cerberus.crud.service.IApplicationService)10 MessageEvent (org.cerberus.engine.entity.MessageEvent)10 AnswerItem (org.cerberus.util.answer.AnswerItem)10 JSONObject (org.json.JSONObject)10 ArrayList (java.util.ArrayList)8 ILogEventService (org.cerberus.crud.service.ILogEventService)7 CerberusException (org.cerberus.exception.CerberusException)7 ApplicationContext (org.springframework.context.ApplicationContext)7 List (java.util.List)6 IFactoryApplication (org.cerberus.crud.factory.IFactoryApplication)6 JSONArray (org.json.JSONArray)6 JSONException (org.json.JSONException)6 Connection (java.sql.Connection)5 ResultSet (java.sql.ResultSet)5 HashMap (java.util.HashMap)5 TestCase (org.cerberus.crud.entity.TestCase)5 Map (java.util.Map)4 TestCaseExecutionQueue (org.cerberus.crud.entity.TestCaseExecutionQueue)4 IFactoryTestCaseExecutionQueue (org.cerberus.crud.factory.IFactoryTestCaseExecutionQueue)4