Search in sources :

Example 6 with ILabelService

use of org.cerberus.crud.service.ILabelService in project cerberus-source by cerberustesting.

the class ReadLabel method findLabelByKey.

private AnswerItem findLabelByKey(Integer id, ApplicationContext appContext, boolean userHasPermissions) throws JSONException, CerberusException {
    AnswerItem item = new AnswerItem();
    JSONObject object = new JSONObject();
    ILabelService labelService = appContext.getBean(ILabelService.class);
    // finds the project
    AnswerItem answer = labelService.readByKey(id);
    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
        Label label = (Label) answer.getItem();
        JSONObject labelObject = convertLabelToJSONObject(label);
        if (!"".equals(label.getParentLabel())) {
            labelObject.put("labelParentObject", convertLabelToJSONObject((Label) labelService.readByKey(Integer.valueOf(label.getParentLabel())).getItem()));
        }
        JSONObject response = labelObject;
        object.put("contentTable", response);
    }
    object.put("hasPermissions", userHasPermissions);
    item.setItem(object);
    item.setResultMessage(answer.getResultMessage());
    return item;
}
Also used : ILabelService(org.cerberus.crud.service.ILabelService) JSONObject(org.json.JSONObject) Label(org.cerberus.crud.entity.Label) AnswerItem(org.cerberus.util.answer.AnswerItem)

Aggregations

ILabelService (org.cerberus.crud.service.ILabelService)6 JSONObject (org.json.JSONObject)6 Label (org.cerberus.crud.entity.Label)5 ILogEventService (org.cerberus.crud.service.ILogEventService)5 MessageEvent (org.cerberus.engine.entity.MessageEvent)5 Answer (org.cerberus.util.answer.Answer)5 AnswerItem (org.cerberus.util.answer.AnswerItem)5 PolicyFactory (org.owasp.html.PolicyFactory)5 ApplicationContext (org.springframework.context.ApplicationContext)5 IOException (java.io.IOException)2 Timestamp (java.sql.Timestamp)2 Date (java.util.Date)2 ServletException (javax.servlet.ServletException)2 TestCaseLabel (org.cerberus.crud.entity.TestCaseLabel)2 IFactoryLabel (org.cerberus.crud.factory.IFactoryLabel)2 IFactoryTestCaseLabel (org.cerberus.crud.factory.IFactoryTestCaseLabel)2 ITestCaseLabelService (org.cerberus.crud.service.ITestCaseLabelService)2 CerberusException (org.cerberus.exception.CerberusException)2 JSONException (org.json.JSONException)2 Application (org.cerberus.crud.entity.Application)1