use of com.netsteadfast.greenstep.vo.WorkspaceConfigVO 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;
}
Aggregations