Search in sources :

Example 1 with InsightsCustomException

use of com.cognizant.devops.platformcommons.exception.InsightsCustomException in project Insights by CognizantOneDevOps.

the class OutComeController method saveOutcomeConfig.

@PostMapping(value = "/saveOutcomeConfig", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public JsonObject saveOutcomeConfig(@RequestBody String config) {
    String message = null;
    try {
        JsonObject configJson = JsonUtils.parseStringAsJsonObject(config);
        int result = outComeServiceImpl.saveOutcomeConfig(configJson);
        log.debug("Outcome config saved successfully === {} ", result);
    } catch (InsightsCustomException e) {
        return PlatformServiceUtil.buildFailureResponse(e.getMessage());
    }
    return PlatformServiceUtil.buildSuccessResponseWithData(message);
}
Also used : InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException) JsonObject(com.google.gson.JsonObject) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with InsightsCustomException

use of com.cognizant.devops.platformcommons.exception.InsightsCustomException in project Insights by CognizantOneDevOps.

the class OutComeServiceImpl method updateOutcomeConfigStatus.

@Override
public void updateOutcomeConfigStatus(JsonObject configJson) throws InsightsCustomException {
    try {
        int outcomeId = configJson.get("id").getAsInt();
        InsightsOutcomeTools insightsOutcomeTools = outComeConfigDAL.getOutcomeConfig(outcomeId);
        insightsOutcomeTools.setIsActive(configJson.get("isActive").getAsBoolean());
        outComeConfigDAL.updateOutcomeConfig(insightsOutcomeTools);
    } catch (Exception e) {
        log.error(e);
        throw new InsightsCustomException(" Error while saving record " + e.getMessage());
    }
}
Also used : InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException) InsightsOutcomeTools(com.cognizant.devops.platformdal.outcome.InsightsOutcomeTools) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException)

Example 3 with InsightsCustomException

use of com.cognizant.devops.platformcommons.exception.InsightsCustomException in project Insights by CognizantOneDevOps.

the class OutComeServiceImpl method updateOutcomeConfig.

@Override
public void updateOutcomeConfig(JsonObject configJson) throws InsightsCustomException {
    try {
        int outcomeId = configJson.get("id").getAsInt();
        InsightsOutcomeTools insightsOutcomeTools = outComeConfigDAL.getOutcomeConfig(outcomeId);
        insightsOutcomeTools.setOutcomeName(configJson.get("outcomeName").getAsString());
        insightsOutcomeTools.setOutcomeType(configJson.get("outcomeType").getAsString());
        insightsOutcomeTools.setConfigJson(configJson.get("toolConfigJson").getAsJsonObject().toString());
        insightsOutcomeTools.setIsActive(configJson.get("isActive").getAsBoolean());
        insightsOutcomeTools.setCreatedDate(configJson.get("createdDate").getAsLong());
        insightsOutcomeTools.setMetricUrl(configJson.get("metricUrl").getAsString());
        insightsOutcomeTools.setUpdatedDate(InsightsUtils.getCurrentTimeInEpochMilliSeconds());
        insightsOutcomeTools.setRequestParameters(configJson.get("parameters").toString());
        outComeConfigDAL.updateOutcomeConfig(insightsOutcomeTools);
    } catch (Exception e) {
        log.error(e);
        throw new InsightsCustomException(" Error while saving record " + e.getMessage());
    }
}
Also used : InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException) InsightsOutcomeTools(com.cognizant.devops.platformdal.outcome.InsightsOutcomeTools) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException)

Example 4 with InsightsCustomException

use of com.cognizant.devops.platformcommons.exception.InsightsCustomException in project Insights by CognizantOneDevOps.

the class OutComeServiceImpl method saveOutcomeConfig.

@Override
public int saveOutcomeConfig(JsonObject configJson) throws InsightsCustomException {
    String outcomeName = configJson.get("outcomeName").getAsString();
    InsightsOutcomeTools outcomeConfig = outComeConfigDAL.getOutComeConfigByName(outcomeName);
    if (outcomeConfig != null) {
        throw new InsightsCustomException("Outcome with given name already exists.");
    }
    InsightsOutcomeTools insightsOutcomeTools = new InsightsOutcomeTools();
    insightsOutcomeTools.setOutcomeName(outcomeName);
    insightsOutcomeTools.setOutcomeType(configJson.get("outcomeType").getAsString());
    insightsOutcomeTools.setConfigJson(configJson.get("toolConfigJson").getAsJsonObject().toString());
    insightsOutcomeTools.setIsActive(configJson.get(MilestoneConstants.ISACTIVE).getAsBoolean());
    insightsOutcomeTools.setMetricUrl(configJson.get("metricUrl").getAsString());
    InsightsTools insightsMilestoneTools = outComeConfigDAL.getOutComeByToolId(configJson.get("toolName").getAsInt());
    insightsOutcomeTools.setInsightsTools(insightsMilestoneTools);
    insightsOutcomeTools.setCreatedDate(InsightsUtils.getCurrentTimeInEpochMilliSeconds());
    insightsOutcomeTools.setRequestParameters(configJson.get("parameters").getAsJsonArray().toString());
    return outComeConfigDAL.saveOutcomeConfig(insightsOutcomeTools);
}
Also used : InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException) InsightsTools(com.cognizant.devops.platformdal.outcome.InsightsTools) InsightsOutcomeTools(com.cognizant.devops.platformdal.outcome.InsightsOutcomeTools)

Example 5 with InsightsCustomException

use of com.cognizant.devops.platformcommons.exception.InsightsCustomException in project Insights by CognizantOneDevOps.

the class OutComeServiceImpl method getAllActiveOutcome.

@Override
public JsonArray getAllActiveOutcome() throws InsightsCustomException {
    try {
        List<InsightsOutcomeTools> configs = outComeConfigDAL.getAllActiveOutcome();
        Gson gson = new Gson();
        JsonElement element = gson.toJsonTree(configs, new TypeToken<List<InsightsOutcomeTools>>() {
        }.getType());
        if (!element.isJsonArray()) {
            throw new InsightsCustomException("Unable to parse Json");
        }
        return element.getAsJsonArray();
    } catch (Exception e) {
        log.error("Error getting milestone list ..", e);
        throw new InsightsCustomException(e.getMessage());
    }
}
Also used : InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException) JsonElement(com.google.gson.JsonElement) TypeToken(com.google.gson.reflect.TypeToken) InsightsOutcomeTools(com.cognizant.devops.platformdal.outcome.InsightsOutcomeTools) Gson(com.google.gson.Gson) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException)

Aggregations

InsightsCustomException (com.cognizant.devops.platformcommons.exception.InsightsCustomException)341 JsonObject (com.google.gson.JsonObject)198 IOException (java.io.IOException)122 JsonArray (com.google.gson.JsonArray)69 FileNotFoundException (java.io.FileNotFoundException)60 JsonElement (com.google.gson.JsonElement)54 ArrayList (java.util.ArrayList)53 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)46 NoResultException (javax.persistence.NoResultException)41 Gson (com.google.gson.Gson)40 PostMapping (org.springframework.web.bind.annotation.PostMapping)40 Test (org.testng.annotations.Test)34 JsonSyntaxException (com.google.gson.JsonSyntaxException)33 HashMap (java.util.HashMap)32 JsonIOException (com.google.gson.JsonIOException)31 File (java.io.File)29 GraphDBHandler (com.cognizant.devops.platformcommons.dal.neo4j.GraphDBHandler)27 SkipException (org.testng.SkipException)25 Map (java.util.Map)21 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)21