Search in sources :

Example 41 with DefaultResult

use of com.netsteadfast.greenstep.base.model.DefaultResult in project bamboobsc by billchen198318.

the class ImportDataLogicServiceImpl method importVisionCsv.

@ServiceMethodAuthority(type = { ServiceMethodType.INSERT, ServiceMethodType.UPDATE })
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = { RuntimeException.class, IOException.class, Exception.class })
@Override
public DefaultResult<Boolean> importVisionCsv(String uploadOid) throws ServiceException, Exception {
    List<Map<String, String>> csvResults = UploadSupportUtils.getTransformSegmentData(uploadOid, "TRAN001");
    if (csvResults.size() < 1) {
        throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.DATA_NO_EXIST));
    }
    boolean success = false;
    DefaultResult<Boolean> result = new DefaultResult<Boolean>();
    StringBuilder msg = new StringBuilder();
    Map<String, Object> paramMap = new HashMap<String, Object>();
    for (int i = 0; i < csvResults.size(); i++) {
        int row = i + 1;
        Map<String, String> data = csvResults.get(i);
        String visId = data.get("VIS_ID");
        String title = data.get("TITLE");
        String content = data.get("CONTENT");
        if (super.isBlank(visId)) {
            msg.append("row: " + row + " id is blank." + Constants.HTML_BR);
            continue;
        }
        if (super.isBlank(title)) {
            msg.append("row: " + row + " title is blank." + Constants.HTML_BR);
            continue;
        }
        if (super.isBlank(content)) {
            msg.append("row: " + row + " content is blank." + Constants.HTML_BR);
            continue;
        }
        VisionVO vision = new VisionVO();
        vision.setVisId(visId);
        vision.setTitle(title);
        vision.setContent(content.getBytes(Constants.BASE_ENCODING));
        paramMap.put("visId", visId);
        if (this.visionService.countByParams(paramMap) > 0) {
            // update
            DefaultResult<VisionVO> oldResult = this.visionService.findByUK(vision);
            vision.setOid(oldResult.getValue().getOid());
            this.visionLogicService.update(vision);
        } else {
            // insert
            this.visionLogicService.create(vision);
        }
        success = true;
    }
    if (msg.length() > 0) {
        result.setSystemMessage(new SystemMessage(msg.toString()));
    } else {
        result.setSystemMessage(new SystemMessage(SysMessageUtil.get(GreenStepSysMsgConstants.UPDATE_SUCCESS)));
    }
    result.setValue(success);
    return result;
}
Also used : SystemMessage(com.netsteadfast.greenstep.base.model.SystemMessage) HashMap(java.util.HashMap) VisionVO(com.netsteadfast.greenstep.vo.VisionVO) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) DefaultResult(com.netsteadfast.greenstep.base.model.DefaultResult) Map(java.util.Map) HashMap(java.util.HashMap) ServiceMethodAuthority(com.netsteadfast.greenstep.base.model.ServiceMethodAuthority) Transactional(org.springframework.transaction.annotation.Transactional)

Example 42 with DefaultResult

use of com.netsteadfast.greenstep.base.model.DefaultResult in project bamboobsc by billchen198318.

the class ImportDataLogicServiceImpl method importKPIsCsv.

@ServiceMethodAuthority(type = { ServiceMethodType.INSERT, ServiceMethodType.UPDATE })
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = { RuntimeException.class, IOException.class, Exception.class })
@Override
public DefaultResult<Boolean> importKPIsCsv(String uploadOid) throws ServiceException, Exception {
    List<Map<String, String>> csvResults = UploadSupportUtils.getTransformSegmentData(uploadOid, "TRAN004");
    if (csvResults.size() < 1) {
        throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.DATA_NO_EXIST));
    }
    List<String> organizationOids = new ArrayList<String>();
    List<String> employeeOids = new ArrayList<String>();
    boolean success = false;
    DefaultResult<Boolean> result = new DefaultResult<Boolean>();
    StringBuilder msg = new StringBuilder();
    // import mode cannot update KPI's attachment/documents, because KPI export no attachment/documents data.
    List<String> kpiAttacDocs = new ArrayList<String>();
    for (int i = 0; i < csvResults.size(); i++) {
        int row = i + 1;
        Map<String, String> data = csvResults.get(i);
        String id = data.get("ID");
        String objId = data.get("OBJ_ID");
        String name = data.get("NAME");
        String weight = data.get("WEIGHT");
        String target = data.get("TARGET");
        String min = data.get("MIN");
        String unit = data.get("UNIT");
        String forId = data.get("FOR_ID");
        String management = data.get("MANAGEMENT");
        String compareType = data.get("COMPARE_TYPE");
        String cal = data.get("CAL");
        String dataType = data.get("DATA_TYPE");
        String orgaMeasureSeparate = data.get("ORGA_MEASURE_SEPARATE");
        String userMeasureSeparate = data.get("USER_MEASURE_SEPARATE");
        String quasiRange = data.get("QUASI_RANGE");
        String description = data.get("DESCRIPTION");
        String max = data.get("MAX");
        String trendsForId = data.get("TRENDS_FOR_ID");
        String activate = data.get("ACTIVATE");
        String errMsg = this.checkKPIsDataError(row, id, objId, name, weight, target, min, unit, forId, management, compareType, cal, dataType, orgaMeasureSeparate, userMeasureSeparate, quasiRange, description, max);
        if (!"".equals(errMsg)) {
            msg.append(errMsg);
            continue;
        }
        ObjectiveVO objective = new ObjectiveVO();
        objective.setObjId(objId);
        DefaultResult<ObjectiveVO> objResult = this.objectiveService.findByUK(objective);
        if (objResult.getValue() == null) {
            throw new ServiceException("row: " + row + " strategy-objectives is not found " + objId);
        }
        objective = objResult.getValue();
        /*
			FormulaVO formula = new FormulaVO();
			formula.setForId(forId);
			DefaultResult<FormulaVO> forResult = this.formulaService.findByUK(formula);
			if ( forResult.getValue() == null ) {
				throw new ServiceException( "row: " + row + " formula is not found " + objId );
			}
			formula = forResult.getValue();
			*/
        KpiVO kpi = new KpiVO();
        kpi.setId(id);
        kpi.setName(name);
        kpi.setWeight(new BigDecimal(weight));
        kpi.setMax(Float.valueOf(max));
        kpi.setTarget(Float.valueOf(target));
        kpi.setMin(Float.valueOf(min));
        kpi.setCompareType(compareType);
        kpi.setUnit(unit);
        kpi.setManagement(management);
        kpi.setQuasiRange(Integer.parseInt(quasiRange));
        kpi.setDataType(dataType);
        kpi.setDescription(description);
        kpi.setOrgaMeasureSeparate(YesNo.NO);
        kpi.setUserMeasureSeparate(YesNo.NO);
        kpi.setActivate(YesNo.NO);
        if (YesNo.YES.equals(orgaMeasureSeparate) || YesNo.YES.equals(userMeasureSeparate)) {
            msg.append("row: " + row + " import mode no support organization/personal measure separate data. please manual settings." + Constants.HTML_BR);
        }
        if (YesNo.YES.equals(activate)) {
            kpi.setActivate(YesNo.YES);
        }
        DefaultResult<KpiVO> kResult = this.kpiService.findByUK(kpi);
        if (kResult.getValue() != null) {
            // update
            kpi.setOid(kResult.getValue().getOid());
            this.kpiLogicService.update(kpi, objective.getOid(), BscFormulaUtils.getFormulaById(forId).getOid(), AggregationMethodUtils.findSimpleById(cal).getOid(), organizationOids, employeeOids, BscFormulaUtils.getFormulaById(trendsForId).getOid(), kpiAttacDocs);
        } else {
            // insert
            this.kpiLogicService.create(kpi, objective.getOid(), BscFormulaUtils.getFormulaById(forId).getOid(), AggregationMethodUtils.findSimpleById(cal).getOid(), organizationOids, employeeOids, BscFormulaUtils.getFormulaById(trendsForId).getOid(), kpiAttacDocs);
        }
        success = true;
    }
    if (msg.length() > 0) {
        result.setSystemMessage(new SystemMessage(msg.toString()));
    } else {
        result.setSystemMessage(new SystemMessage(SysMessageUtil.get(GreenStepSysMsgConstants.UPDATE_SUCCESS)));
    }
    result.setValue(success);
    return result;
}
Also used : SystemMessage(com.netsteadfast.greenstep.base.model.SystemMessage) ObjectiveVO(com.netsteadfast.greenstep.vo.ObjectiveVO) ArrayList(java.util.ArrayList) KpiVO(com.netsteadfast.greenstep.vo.KpiVO) BigDecimal(java.math.BigDecimal) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) DefaultResult(com.netsteadfast.greenstep.base.model.DefaultResult) Map(java.util.Map) HashMap(java.util.HashMap) ServiceMethodAuthority(com.netsteadfast.greenstep.base.model.ServiceMethodAuthority) Transactional(org.springframework.transaction.annotation.Transactional)

Example 43 with DefaultResult

use of com.netsteadfast.greenstep.base.model.DefaultResult in project bamboobsc by billchen198318.

the class ImportDataLogicServiceImpl method importPerspectivesCsv.

@ServiceMethodAuthority(type = { ServiceMethodType.INSERT, ServiceMethodType.UPDATE })
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = { RuntimeException.class, IOException.class, Exception.class })
@Override
public DefaultResult<Boolean> importPerspectivesCsv(String uploadOid) throws ServiceException, Exception {
    List<Map<String, String>> csvResults = UploadSupportUtils.getTransformSegmentData(uploadOid, "TRAN002");
    if (csvResults.size() < 1) {
        throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.DATA_NO_EXIST));
    }
    boolean success = false;
    DefaultResult<Boolean> result = new DefaultResult<Boolean>();
    StringBuilder msg = new StringBuilder();
    Map<String, Object> paramMap = new HashMap<String, Object>();
    for (int i = 0; i < csvResults.size(); i++) {
        int row = i + 1;
        Map<String, String> data = csvResults.get(i);
        String perId = data.get("PER_ID");
        String visId = data.get("VIS_ID");
        String name = data.get("NAME");
        String weight = data.get("WEIGHT");
        String target = data.get("TARGET");
        String min = data.get("MIN");
        String description = data.get("DESCRIPTION");
        if (super.isBlank(perId)) {
            msg.append("row: " + row + " perspective-id is blank." + Constants.HTML_BR);
            continue;
        }
        if (super.isBlank(visId)) {
            msg.append("row: " + row + " vision-id is blank." + Constants.HTML_BR);
            continue;
        }
        if (super.isBlank(name)) {
            msg.append("row: " + row + " name is blank." + Constants.HTML_BR);
            continue;
        }
        if (super.isBlank(weight)) {
            msg.append("row: " + row + " weight is blank." + Constants.HTML_BR);
            continue;
        }
        if (super.isBlank(target)) {
            msg.append("row: " + row + " target is blank." + Constants.HTML_BR);
            continue;
        }
        if (super.isBlank(min)) {
            msg.append("row: " + row + " min is blank." + Constants.HTML_BR);
            continue;
        }
        if (!NumberUtils.isNumber(weight)) {
            msg.append("row: " + row + " weight is not number." + Constants.HTML_BR);
            continue;
        }
        if (!NumberUtils.isNumber(target)) {
            msg.append("row: " + row + " target is not number." + Constants.HTML_BR);
            continue;
        }
        if (!NumberUtils.isNumber(min)) {
            msg.append("row: " + row + " min is not number." + Constants.HTML_BR);
            continue;
        }
        paramMap.clear();
        paramMap.put("visId", visId);
        if (this.visionService.countByParams(paramMap) < 1) {
            throw new ServiceException("row: " + row + " vision is not found " + visId);
        }
        DefaultResult<VisionVO> visionResult = this.visionService.findForSimpleByVisId(visId);
        if (visionResult.getValue() == null) {
            throw new ServiceException(visionResult.getSystemMessage().getValue());
        }
        PerspectiveVO perspective = new PerspectiveVO();
        perspective.setPerId(perId);
        perspective.setVisId(visId);
        perspective.setName(name);
        perspective.setWeight(new BigDecimal(weight));
        perspective.setTarget(Float.valueOf(target));
        perspective.setMin(Float.valueOf(min));
        perspective.setDescription(description);
        paramMap.clear();
        paramMap.put("perId", perId);
        if (this.perspectiveService.countByParams(paramMap) > 0) {
            // update
            DefaultResult<PerspectiveVO> oldResult = this.perspectiveService.findByUK(perspective);
            perspective.setOid(oldResult.getValue().getOid());
            this.perspectiveLogicService.update(perspective, visionResult.getValue().getOid());
        } else {
            // insert
            this.perspectiveLogicService.create(perspective, visionResult.getValue().getOid());
        }
        success = true;
    }
    if (msg.length() > 0) {
        result.setSystemMessage(new SystemMessage(msg.toString()));
    } else {
        result.setSystemMessage(new SystemMessage(SysMessageUtil.get(GreenStepSysMsgConstants.UPDATE_SUCCESS)));
    }
    result.setValue(success);
    return result;
}
Also used : SystemMessage(com.netsteadfast.greenstep.base.model.SystemMessage) HashMap(java.util.HashMap) PerspectiveVO(com.netsteadfast.greenstep.vo.PerspectiveVO) VisionVO(com.netsteadfast.greenstep.vo.VisionVO) BigDecimal(java.math.BigDecimal) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) DefaultResult(com.netsteadfast.greenstep.base.model.DefaultResult) Map(java.util.Map) HashMap(java.util.HashMap) ServiceMethodAuthority(com.netsteadfast.greenstep.base.model.ServiceMethodAuthority) Transactional(org.springframework.transaction.annotation.Transactional)

Example 44 with DefaultResult

use of com.netsteadfast.greenstep.base.model.DefaultResult in project bamboobsc by billchen198318.

the class ImportDataLogicServiceImpl method importObjectivesCsv.

@ServiceMethodAuthority(type = { ServiceMethodType.INSERT, ServiceMethodType.UPDATE })
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = { RuntimeException.class, IOException.class, Exception.class })
@Override
public DefaultResult<Boolean> importObjectivesCsv(String uploadOid) throws ServiceException, Exception {
    List<Map<String, String>> csvResults = UploadSupportUtils.getTransformSegmentData(uploadOid, "TRAN003");
    if (csvResults.size() < 1) {
        throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.DATA_NO_EXIST));
    }
    boolean success = false;
    DefaultResult<Boolean> result = new DefaultResult<Boolean>();
    StringBuilder msg = new StringBuilder();
    for (int i = 0; i < csvResults.size(); i++) {
        int row = i + 1;
        Map<String, String> data = csvResults.get(i);
        String objId = data.get("OBJ_ID");
        String perId = data.get("PER_ID");
        String name = data.get("NAME");
        String weight = data.get("WEIGHT");
        String target = data.get("TARGET");
        String min = data.get("MIN");
        String description = data.get("DESCRIPTION");
        if (super.isBlank(objId)) {
            msg.append("row: " + row + " objective-id is blank." + Constants.HTML_BR);
            continue;
        }
        if (super.isBlank(perId)) {
            msg.append("row: " + row + " perspective-id is blank." + Constants.HTML_BR);
            continue;
        }
        if (super.isBlank(name)) {
            msg.append("row: " + row + " name is blank." + Constants.HTML_BR);
            continue;
        }
        if (super.isBlank(weight)) {
            msg.append("row: " + row + " weight is blank." + Constants.HTML_BR);
            continue;
        }
        if (super.isBlank(target)) {
            msg.append("row: " + row + " target is blank." + Constants.HTML_BR);
            continue;
        }
        if (super.isBlank(min)) {
            msg.append("row: " + row + " min is blank." + Constants.HTML_BR);
            continue;
        }
        if (!NumberUtils.isNumber(weight)) {
            msg.append("row: " + row + " weight is not number." + Constants.HTML_BR);
            continue;
        }
        if (!NumberUtils.isNumber(target)) {
            msg.append("row: " + row + " target is not number." + Constants.HTML_BR);
            continue;
        }
        if (!NumberUtils.isNumber(min)) {
            msg.append("row: " + row + " min is not number." + Constants.HTML_BR);
            continue;
        }
        PerspectiveVO perspective = new PerspectiveVO();
        perspective.setPerId(perId);
        DefaultResult<PerspectiveVO> perResult = this.perspectiveService.findByUK(perspective);
        if (perResult.getValue() == null) {
            throw new ServiceException("row: " + row + " perspective is not found " + perId);
        }
        perspective = perResult.getValue();
        ObjectiveVO objective = new ObjectiveVO();
        objective.setObjId(objId);
        DefaultResult<ObjectiveVO> oldResult = this.objectiveService.findByUK(objective);
        objective.setObjId(objId);
        objective.setPerId(perId);
        objective.setName(name);
        objective.setWeight(new BigDecimal(weight));
        objective.setTarget(Float.valueOf(target));
        objective.setMin(Float.valueOf(min));
        objective.setDescription(description);
        if (oldResult.getValue() != null) {
            // update
            objective.setOid(oldResult.getValue().getOid());
            this.objectiveLogicService.update(objective, perspective.getOid());
        } else {
            // insert
            this.objectiveLogicService.create(objective, perspective.getOid());
        }
        success = true;
    }
    if (msg.length() > 0) {
        result.setSystemMessage(new SystemMessage(msg.toString()));
    } else {
        result.setSystemMessage(new SystemMessage(SysMessageUtil.get(GreenStepSysMsgConstants.UPDATE_SUCCESS)));
    }
    result.setValue(success);
    return result;
}
Also used : SystemMessage(com.netsteadfast.greenstep.base.model.SystemMessage) ObjectiveVO(com.netsteadfast.greenstep.vo.ObjectiveVO) PerspectiveVO(com.netsteadfast.greenstep.vo.PerspectiveVO) BigDecimal(java.math.BigDecimal) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) DefaultResult(com.netsteadfast.greenstep.base.model.DefaultResult) Map(java.util.Map) HashMap(java.util.HashMap) ServiceMethodAuthority(com.netsteadfast.greenstep.base.model.ServiceMethodAuthority) Transactional(org.springframework.transaction.annotation.Transactional)

Example 45 with DefaultResult

use of com.netsteadfast.greenstep.base.model.DefaultResult in project bamboobsc by billchen198318.

the class VisionServiceImpl method findForSimple.

@Override
public DefaultResult<VisionVO> findForSimple(String oid) throws ServiceException, Exception {
    if (StringUtils.isBlank(oid)) {
        throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.PARAMS_BLANK));
    }
    DefaultResult<VisionVO> result = new DefaultResult<VisionVO>();
    VisionVO vision = this.visionDAO.findForSimple(oid);
    if (vision != null) {
        result.setValue(vision);
    } else {
        result.setSystemMessage(new SystemMessage(SysMessageUtil.get(GreenStepSysMsgConstants.SEARCH_NO_DATA)));
    }
    return result;
}
Also used : SystemMessage(com.netsteadfast.greenstep.base.model.SystemMessage) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) DefaultResult(com.netsteadfast.greenstep.base.model.DefaultResult) VisionVO(com.netsteadfast.greenstep.vo.VisionVO)

Aggregations

DefaultResult (com.netsteadfast.greenstep.base.model.DefaultResult)52 SystemMessage (com.netsteadfast.greenstep.base.model.SystemMessage)50 ServiceException (com.netsteadfast.greenstep.base.exception.ServiceException)48 Transactional (org.springframework.transaction.annotation.Transactional)32 ServiceMethodAuthority (com.netsteadfast.greenstep.base.model.ServiceMethodAuthority)29 HashMap (java.util.HashMap)13 List (java.util.List)12 Map (java.util.Map)9 VisionVO (com.netsteadfast.greenstep.vo.VisionVO)7 ArrayList (java.util.ArrayList)7 BaseEntity (com.netsteadfast.greenstep.base.model.BaseEntity)6 IOException (java.io.IOException)6 BaseValueObj (com.netsteadfast.greenstep.base.model.BaseValueObj)5 AggregationMethodVO (com.netsteadfast.greenstep.vo.AggregationMethodVO)3 KpiVO (com.netsteadfast.greenstep.vo.KpiVO)3 MeasureDataVO (com.netsteadfast.greenstep.vo.MeasureDataVO)3 ObjectiveVO (com.netsteadfast.greenstep.vo.ObjectiveVO)3 OrganizationVO (com.netsteadfast.greenstep.vo.OrganizationVO)3 PerspectiveVO (com.netsteadfast.greenstep.vo.PerspectiveVO)3 RoleVO (com.netsteadfast.greenstep.vo.RoleVO)3