troubleshooting Question

how to write the below code in an effective way in java

Avatar of srikotesh
srikotesh asked on
JavaJava EE
5 Comments1 Solution97 ViewsLast Modified:
Hi Experts,

Can some one suggest me how can i write below code in an effective way.

whenever i call this method i will get any of the status it may be 1 or 2 or 3....8
public Integer getContentStatus(int ContentId) {
        int status = 0;
        String success = "";
        Object ContentStatus = ContentDao.getContentByStatus(ContentId);
        if (ContentStatus != null) {
            Object[] row = (Object[]) ContentStatus;
            String taskStatus = (String) row[1];
            if (row[2] == null) {
                success = null;
            }
            else {
                success = String.valueOf((Integer) row[2]);
            }
            String actionStatus = (String) row[3];
            Date scheduleTime = (Date) row[4];
            String actionSubStatus = actionStatus.substring(9);
            String taskResult = taskStatus.substring(5);
            if ("COMP".equals(taskResult)) {
                return status = 1;
            }
            else if ("NOTCOMP".equals(taskResult) && MWatchUtil.isNullOrEmpty(String.valueOf(success))) {
                return status = 8;
            }
            else if ("NOTCOMP".equals(taskResult) && success == "0") {
                return status = 2;
            }
            else if ("IDLE".equals(taskResult)) {
                if ("ABO".equals(actionSubStatus)) {
                    return status = 3;
                }
                else if ("RUN".equals(actionSubStatus)) {
                    return status = 4;
                }
                else if ("INIT".equals(actionSubStatus)) {
                    return status = 5;
                }
                else if ("SCH".equals(actionSubStatus)) {
                    return status = 6;
                }
                else if ("IDLE".equals(actionSubStatus)) {
                    if (IsScheduleTimeLessThanCurrentTime(scheduleTime)) {
                        return status = 8;
                    }
                }
                else {
                    return status = 4;
                }
            }
            else {
                return status = 7;
            }
        }
        return null;
    }


From this method i will display  counts status to the user.
success count ---8
failure count ---3 like that i am going return map with count

From this method i am going to call the above method to get the status id

public Map<String, Integer> getContentStatusCount(List<Integer> customerids) {
        int success, failureByLogic, aborted, running, initiated, scheduled, yetToStart, failureBySystem;
        success = failureByLogic = aborted = running = initiated = scheduled = yetToStart = failureBySystem = 0;
        List<Object> ContentStatusInfo = ContentDao.getContentByStatusInfo(customerids);
        if (!ContentStatusInfo.isEmpty()) {
            for (Object object : ContentStatusInfo) {
                Integer ContentIds = (Integer) object;
                if (ContentServiceHelper.getContentStatus(ContentIds) != null) {
                    int statusvalue = ContentServiceHelper.getContentStatus(ContentIds);
                    if (statusvalue == 1) {
                        success++;
                    }
                    else if (statusvalue == 2) {
                        failureByLogic++;
                    }
                    else if (statusvalue == 3) {
                        aborted++;
                    }
                    else if (statusvalue == 4) {
                        running++;
                    }
                    else if (statusvalue == 5) {
                        initiated++;
                    }
                    else if (statusvalue == 6) {
                        scheduled++;
                    }
                    else if (statusvalue == 7) {
                        yetToStart++;
                    }
                    else if (statusvalue == 8) {
                        failureBySystem++;
                    }
                }
            }
        }
        Map<String, Integer> ContentStatusMap = new HashMap<>();
        ContentStatusMap.put(ContentApprovalStatusEnum.getById(1), success);
        ContentStatusMap.put(ContentApprovalStatusEnum.getById(2), failureByLogic);
        ContentStatusMap.put(ContentApprovalStatusEnum.getById(3), aborted);
        ContentStatusMap.put(ContentApprovalStatusEnum.getById(4), running);
        ContentStatusMap.put(ContentApprovalStatusEnum.getById(5), initiated);
        ContentStatusMap.put(ContentApprovalStatusEnum.getById(6), scheduled);
        ContentStatusMap.put(ContentApprovalStatusEnum.getById(7), yetToStart);
        ContentStatusMap.put(ContentApprovalStatusEnum.getById(8), failureBySystem);
        LOGGER.debug("ContentStatusMap is {}", ContentStatusMap);
        return ContentStatusMap;
    }

Thanks,
ASKER CERTIFIED SOLUTION
dpearson

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros