use of com.webank.wedatasphere.qualitis.project.entity.Project in project Qualitis by WeBankFinTech.
the class OuterWorkflowProjectServiceImpl method addWorkflowProject.
@Override
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { RuntimeException.class, UnExpectedRequestException.class, RoleNotFoundException.class })
public GeneralResponse<ProjectDetailResponse> addWorkflowProject(AddProjectRequest request, String username) throws UnExpectedRequestException, RoleNotFoundException, PermissionDeniedRequestException {
LOGGER.info("Add workflow project request: " + new Gson().toJson(request));
// Check Arguments
Set<String> labels = request.getProjectLabels();
AddProjectRequest.checkRequest(request);
if (request.getUsername() == null) {
throw new UnExpectedRequestException("Username: {&CAN_NOT_BE_NULL_OR_EMPTY}");
}
// Check existence of user
User userInDb = userDao.findByUsername(username);
if (userInDb == null) {
userService.autoAddUser(username);
userInDb = userDao.findByUsername(username);
}
// Check existence of project by project name.
Project projectInDb = projectDao.findByNameAndCreateUser(request.getProjectName(), username);
boolean needSuffix = false;
if (projectInDb != null) {
if (projectInDb.getProjectType().equals(ProjectTypeEnum.WORKFLOW_PROJECT.getCode())) {
ProjectDetailResponse response = new ProjectDetailResponse(projectInDb, null);
LOGGER.info("Succeed to find exists workflow project, response: {}", response);
return new GeneralResponse<>("200", "{&GET_PROJECT_DETAIL_SUCCESSFULLY}", response);
} else {
needSuffix = true;
}
}
Project newProject = projectService.addProjectReal(userInDb.getId(), needSuffix ? request.getProjectName() + "_workflow" : request.getProjectName(), request.getCnName(), request.getDescription());
newProject.setProjectType(ProjectTypeEnum.WORKFLOW_PROJECT.getCode());
Project savedProject = projectDao.saveProject(newProject);
projectService.addProjectLabels(labels, savedProject);
// Authorized users.
projectService.authorizeUsers(savedProject, userInDb, request.getAuthorizeProjectUserRequests(), false);
ProjectDetailResponse response = new ProjectDetailResponse(savedProject, null);
LOGGER.info("Succeed to add workflow project, response: {}", response);
return new GeneralResponse<>("200", "{&ADD_PROJECT_SUCCESSFULLY}", response);
}
use of com.webank.wedatasphere.qualitis.project.entity.Project in project Qualitis by WeBankFinTech.
the class OuterWorkflowProjectServiceImpl method getWorkflowProject.
@Override
public GeneralResponse<ProjectDetailResponse> getWorkflowProject(GetProjectRequest request) throws UnExpectedRequestException {
GetProjectRequest.checkRequest(request);
Project projectInDb = projectDao.findByNameAndCreateUser(request.getName(), request.getUsername());
if (projectInDb == null) {
return new GeneralResponse<>("200", "{&GET_PROJECT_DETAIL_SUCCESSFULLY}", new ProjectDetailResponse(Long.parseLong("-1")));
}
return new GeneralResponse<>("200", "{&GET_PROJECT_DETAIL_SUCCESSFULLY}", new ProjectDetailResponse(projectInDb));
}
use of com.webank.wedatasphere.qualitis.project.entity.Project in project Qualitis by WeBankFinTech.
the class ProjectBatchServiceImpl method getExcelMultiTemplateRuleByProject.
private List<ExcelMultiTemplateRuleByProject> getExcelMultiTemplateRuleByProject(List<Project> projects, String localeStr) {
List<ExcelMultiTemplateRuleByProject> excelMultiTemplateRuleByProjects = new ArrayList<>();
for (Project project : projects) {
List<Rule> rules = ruleDao.findByProject(project);
List<ExcelMultiTemplateRuleByProject> excelMultiTemplateRules = ruleBatchService.getMultiTemplateRule(rules, localeStr);
for (ExcelMultiTemplateRuleByProject excelMultiTemplateRule : excelMultiTemplateRules) {
ExcelMultiTemplateRuleByProject excelMultiTemplateRuleByProject = new ExcelMultiTemplateRuleByProject();
BeanUtils.copyProperties(excelMultiTemplateRule, excelMultiTemplateRuleByProject);
excelMultiTemplateRuleByProject.setProjectName(project.getName());
LOGGER.info("Collect excel line of custom rule: {}", excelMultiTemplateRuleByProject);
excelMultiTemplateRuleByProjects.add(excelMultiTemplateRuleByProject);
}
}
return excelMultiTemplateRuleByProjects;
}
use of com.webank.wedatasphere.qualitis.project.entity.Project in project Qualitis by WeBankFinTech.
the class ProjectBatchServiceImpl method getExcelProject.
private List<ExcelProject> getExcelProject(List<Project> projects) {
List<ExcelProject> excelProjects = new ArrayList<>();
for (Project project : projects) {
ExcelProject excelProject = new ExcelProject();
excelProject.setProjectName(project.getName());
excelProject.setProjectDescription(project.getDescription());
Set<ProjectLabel> projectLabels = project.getProjectLabels();
StringBuffer labelBuffer = new StringBuffer();
if (projectLabels != null && !projectLabels.isEmpty()) {
for (ProjectLabel projectLabel : projectLabels) {
labelBuffer.append(projectLabel.getLabelName() + " ");
}
excelProject.setProjectLabels(labelBuffer.toString());
}
LOGGER.info("Collect excel line: {}", excelProject);
excelProjects.add(excelProject);
}
return excelProjects;
}
use of com.webank.wedatasphere.qualitis.project.entity.Project in project Qualitis by WeBankFinTech.
the class ProjectBatchServiceImpl method downloadProjects.
@Override
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> downloadProjects(DownloadProjectRequest request, HttpServletResponse response) throws UnExpectedRequestException, WriteExcelException, IOException, PermissionDeniedRequestException {
// Check Arguments
DownloadProjectRequest.checkRequest(request);
String loginUser = HttpUtils.getUserName(httpServletRequest);
List<Project> projectsInDb = new ArrayList<>();
for (Long projectId : request.getProjectId()) {
Project projectInDb = projectDao.findById(projectId);
if (projectInDb == null) {
throw new UnExpectedRequestException("{&PROJECT_ID} : [" + projectId + "] {&DOES_NOT_EXIST}");
}
// Check permissions of project
List<Integer> permissions = new ArrayList<>();
permissions.add(ProjectUserPermissionEnum.DEVELOPER.getCode());
projectService.checkProjectPermission(projectInDb, loginUser, permissions);
projectsInDb.add(projectInDb);
}
// Write project and rules
return writeProjectAndRules(projectsInDb, response);
}
Aggregations