Search in sources :

Example 1 with WorkspaceLabelVO

use of com.netsteadfast.greenstep.vo.WorkspaceLabelVO in project bamboobsc by billchen198318.

the class WorkspaceLogicServiceImpl method create.

@ServiceMethodAuthority(type = { ServiceMethodType.INSERT })
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = { RuntimeException.class, IOException.class, Exception.class })
@SuppressWarnings("unchecked")
@Override
public DefaultResult<WorkspaceVO> create(String spaceId, String name, String description, String workspaceTemplateOid, Map<String, Object> jsonData) throws ServiceException, Exception {
    if (super.isBlank(spaceId) || super.isBlank(name) || super.isNoSelectId(workspaceTemplateOid) || jsonData == null || jsonData.size() < 1) {
        throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.PARAMS_BLANK));
    }
    if (jsonData.get("nodes") == null || !(jsonData.get("nodes") instanceof List)) {
        throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.PARAMS_BLANK));
    }
    if (jsonData.get("labels") == null || !(jsonData.get("labels") instanceof List)) {
        throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.PARAMS_BLANK));
    }
    WorkspaceTemplateVO template = new WorkspaceTemplateVO();
    template.setOid(workspaceTemplateOid);
    DefaultResult<WorkspaceTemplateVO> wtResult = this.workspaceTemplateService.findObjectByOid(template);
    if (wtResult.getValue() == null) {
        throw new ServiceException(wtResult.getSystemMessage().getValue());
    }
    template = wtResult.getValue();
    WorkspaceVO workspace = new WorkspaceVO();
    workspace.setSpaceId(spaceId);
    workspace.setTemplateId(template.getTemplateId());
    workspace.setName(name);
    workspace.setDescription(super.defaultString(description));
    this.setStringValueMaxLength(workspace, "description", MAX_DESCRIPTION_LENGTH);
    DefaultResult<WorkspaceVO> result = this.workspaceService.saveObject(workspace);
    if (result.getValue() == null) {
        throw new ServiceException(result.getSystemMessage().getValue());
    }
    workspace = result.getValue();
    List<Map<String, Object>> nodes = (List<Map<String, Object>>) jsonData.get("nodes");
    List<Map<String, Object>> labels = (List<Map<String, Object>>) jsonData.get("labels");
    for (int i = 0; nodes != null && i < nodes.size(); i++) {
        Map<String, Object> data = nodes.get(i);
        String id = (String) data.get("id");
        int position = Integer.parseInt(String.valueOf(data.get("position")));
        BbWorkspaceCompoment compoment = new BbWorkspaceCompoment();
        compoment.setCompId(id);
        if (this.workspaceCompomentService.countByEntityUK(compoment) < 1) {
            throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.DATA_ERRORS));
        }
        WorkspaceConfigVO configObj = new WorkspaceConfigVO();
        configObj.setSpaceId(workspace.getSpaceId());
        configObj.setCompId(id);
        configObj.setPosition(position);
        this.workspaceConfigService.saveObject(configObj);
    }
    for (int i = 0; labels != null && i < labels.size(); i++) {
        Map<String, Object> data = labels.get(i);
        String label = (String) data.get("label");
        int position = Integer.parseInt(String.valueOf(data.get("position")));
        if (StringUtils.isBlank(label)) {
            label = "   ";
        }
        WorkspaceLabelVO labelObj = new WorkspaceLabelVO();
        labelObj.setSpaceId(workspace.getSpaceId());
        labelObj.setLabel(label);
        labelObj.setPosition(position);
        this.workspaceLabelService.saveIgnoreUK(labelObj);
    }
    return result;
}
Also used : BbWorkspaceCompoment(com.netsteadfast.greenstep.po.hbm.BbWorkspaceCompoment) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) WorkspaceTemplateVO(com.netsteadfast.greenstep.vo.WorkspaceTemplateVO) WorkspaceVO(com.netsteadfast.greenstep.vo.WorkspaceVO) WorkspaceLabelVO(com.netsteadfast.greenstep.vo.WorkspaceLabelVO) List(java.util.List) WorkspaceConfigVO(com.netsteadfast.greenstep.vo.WorkspaceConfigVO) HashMap(java.util.HashMap) Map(java.util.Map) ServiceMethodAuthority(com.netsteadfast.greenstep.base.model.ServiceMethodAuthority) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ServiceException (com.netsteadfast.greenstep.base.exception.ServiceException)1 ServiceMethodAuthority (com.netsteadfast.greenstep.base.model.ServiceMethodAuthority)1 BbWorkspaceCompoment (com.netsteadfast.greenstep.po.hbm.BbWorkspaceCompoment)1 WorkspaceConfigVO (com.netsteadfast.greenstep.vo.WorkspaceConfigVO)1 WorkspaceLabelVO (com.netsteadfast.greenstep.vo.WorkspaceLabelVO)1 WorkspaceTemplateVO (com.netsteadfast.greenstep.vo.WorkspaceTemplateVO)1 WorkspaceVO (com.netsteadfast.greenstep.vo.WorkspaceVO)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Transactional (org.springframework.transaction.annotation.Transactional)1