Search in sources :

Example 1 with SkillDTO

use of com.odysseusinc.arachne.portal.api.v1.dto.dictionary.SkillDTO in project ArachneCentralAPI by OHDSI.

the class BaseSkillController method update.

@ApiOperation(value = "Update skill description.", hidden = true)
@RequestMapping(value = "/api/v1/admin/skills/{skillId}", method = RequestMethod.PUT)
public JsonResult<SkillDTO> update(@PathVariable("skillId") Long id, @RequestBody @Valid SkillDTO skillDTO, BindingResult binding) throws NotExistException, NotUniqueException, ValidationException {
    JsonResult<SkillDTO> result;
    if (binding.hasErrors()) {
        result = new JsonResult<>(JsonResult.ErrorCode.VALIDATION_ERROR);
        for (FieldError fieldError : binding.getFieldErrors()) {
            result.getValidatorErrors().put(fieldError.getField(), fieldError.getDefaultMessage());
        }
    } else {
        skillDTO.setId(id);
        S skill = convertDtoToSkill(skillDTO);
        skill = skillService.update(skill);
        result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
        result.setResult(conversionService.convert(skill, SkillDTO.class));
    }
    return result;
}
Also used : SkillDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.SkillDTO) FieldError(org.springframework.validation.FieldError) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with SkillDTO

use of com.odysseusinc.arachne.portal.api.v1.dto.dictionary.SkillDTO in project ArachneCentralAPI by OHDSI.

the class SkillToSkillDTOConverter method convert.

@Override
public SkillDTO convert(Skill source) {
    SkillDTO skillDTO = new SkillDTO();
    skillDTO.setId(source.getId());
    skillDTO.setName(source.getName());
    return skillDTO;
}
Also used : SkillDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.SkillDTO)

Example 3 with SkillDTO

use of com.odysseusinc.arachne.portal.api.v1.dto.dictionary.SkillDTO in project ArachneCentralAPI by OHDSI.

the class UserToUserProfileDTOConverter method convert.

@Override
public UserProfileDTO convert(IUser user) {
    UserProfileDTO dto = new UserProfileDTO();
    dto.setId(user.getUuid());
    dto.setEnabled(user.getEnabled());
    dto.setCreated(user.getCreated());
    dto.setUpdated(user.getUpdated());
    HashSet<SkillDTO> skills = new HashSet<>();
    for (Skill skill : user.getSkills()) {
        skills.add(conversionService.convert(skill, SkillDTO.class));
    }
    dto.setSkills(skills);
    LinkedList<UserPublicationDTO> publications = new LinkedList<>();
    for (UserPublication userPublication : user.getPublications()) {
        publications.add(conversionService.convert(userPublication, UserPublicationDTO.class));
    }
    dto.setPublications(publications);
    LinkedList<UserLinkDTO> links = new LinkedList<>();
    for (UserLink userLink : user.getLinks()) {
        links.add(conversionService.convert(userLink, UserLinkDTO.class));
    }
    dto.setLinks(links);
    dto.setGeneral(conversionService.convert(user, UserProfileGeneralDTO.class));
    return dto;
}
Also used : SkillDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.SkillDTO) UserLinkDTO(com.odysseusinc.arachne.portal.api.v1.dto.UserLinkDTO) UserProfileDTO(com.odysseusinc.arachne.portal.api.v1.dto.UserProfileDTO) LinkedList(java.util.LinkedList) UserPublication(com.odysseusinc.arachne.portal.model.UserPublication) UserLink(com.odysseusinc.arachne.portal.model.UserLink) Skill(com.odysseusinc.arachne.portal.model.Skill) UserProfileGeneralDTO(com.odysseusinc.arachne.portal.api.v1.dto.UserProfileGeneralDTO) UserPublicationDTO(com.odysseusinc.arachne.portal.api.v1.dto.UserPublicationDTO) HashSet(java.util.HashSet)

Example 4 with SkillDTO

use of com.odysseusinc.arachne.portal.api.v1.dto.dictionary.SkillDTO in project ArachneCentralAPI by OHDSI.

the class SkillControllerTests method testCreateSkill.

@Test
@DatabaseSetup("/data/skill/empty-skill.xml")
@ExpectedDatabase(value = "/data/skill/added-skill.xml", assertionMode = NON_STRICT)
public void testCreateSkill() throws Exception {
    SkillDTO skillDTO = new SkillDTO();
    skillDTO.setName(SKILL_NAME);
    MvcResult mvcResult = mvc.perform(post("/api/v1/user-management/skills/").contentType(APPLICATION_JSON).content(objectMapper.writeValueAsBytes(skillDTO))).andExpect(jsonPath("$.result.id").isNotEmpty()).andExpect(OK_STATUS).andExpect(NO_ERROR_CODE).andReturn();
    JSONAssert.assertEquals(SKILL_JSON_OBJECT, getResultJSONObject(mvcResult), false);
}
Also used : SkillDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.SkillDTO) MvcResult(org.springframework.test.web.servlet.MvcResult) ExpectedDatabase(com.github.springtestdbunit.annotation.ExpectedDatabase) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup)

Example 5 with SkillDTO

use of com.odysseusinc.arachne.portal.api.v1.dto.dictionary.SkillDTO in project ArachneCentralAPI by OHDSI.

the class BaseSkillController method create.

@ApiOperation("Register new skill.")
@RequestMapping(value = "/api/v1/user-management/skills", method = RequestMethod.POST)
public JsonResult<SkillDTO> create(@RequestBody @Valid SkillDTO skillDTO, BindingResult binding) throws NotExistException, NotUniqueException, PermissionDeniedException {
    JsonResult<SkillDTO> result;
    if (binding.hasErrors()) {
        result = new JsonResult<>(JsonResult.ErrorCode.VALIDATION_ERROR);
        for (FieldError fieldError : binding.getFieldErrors()) {
            result.getValidatorErrors().put(fieldError.getField(), fieldError.getDefaultMessage());
        }
    } else {
        S skill = convertDtoToSkill(skillDTO);
        skill = skillService.create(skill);
        result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
        result.setResult(conversionService.convert(skill, SkillDTO.class));
    }
    return result;
}
Also used : SkillDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.SkillDTO) FieldError(org.springframework.validation.FieldError) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

SkillDTO (com.odysseusinc.arachne.portal.api.v1.dto.dictionary.SkillDTO)7 DatabaseSetup (com.github.springtestdbunit.annotation.DatabaseSetup)2 ExpectedDatabase (com.github.springtestdbunit.annotation.ExpectedDatabase)2 Skill (com.odysseusinc.arachne.portal.model.Skill)2 ApiOperation (io.swagger.annotations.ApiOperation)2 HashSet (java.util.HashSet)2 Test (org.junit.Test)2 MvcResult (org.springframework.test.web.servlet.MvcResult)2 FieldError (org.springframework.validation.FieldError)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 UserLinkDTO (com.odysseusinc.arachne.portal.api.v1.dto.UserLinkDTO)1 UserProfileDTO (com.odysseusinc.arachne.portal.api.v1.dto.UserProfileDTO)1 UserProfileGeneralDTO (com.odysseusinc.arachne.portal.api.v1.dto.UserProfileGeneralDTO)1 UserPublicationDTO (com.odysseusinc.arachne.portal.api.v1.dto.UserPublicationDTO)1 User (com.odysseusinc.arachne.portal.model.User)1 UserLink (com.odysseusinc.arachne.portal.model.UserLink)1 UserPublication (com.odysseusinc.arachne.portal.model.UserPublication)1 LinkedList (java.util.LinkedList)1