Search in sources :

Example 1 with UserLinkDTO

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

the class UserLinkToLinkDTOConverter method convert.

@Override
public UserLinkDTO convert(UserLink userLink) {
    UserLinkDTO dto = new UserLinkDTO();
    dto.setDescription(userLink.getDescription());
    dto.setTitle(userLink.getTitle());
    dto.setId(userLink.getId());
    dto.setUrl(userLink.getUrl());
    return dto;
}
Also used : UserLinkDTO(com.odysseusinc.arachne.portal.api.v1.dto.UserLinkDTO)

Example 2 with UserLinkDTO

use of com.odysseusinc.arachne.portal.api.v1.dto.UserLinkDTO 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 3 with UserLinkDTO

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

the class UserControllerTests method testLinkToUser.

@Test
@WithUserDetails(value = ADMIN_EMAIL)
@DatabaseSetup("/data/user/admin-user.xml")
@ExpectedDatabase(value = "/data/user/admin-user-with-link.xml", assertionMode = NON_STRICT)
public void testLinkToUser() throws Exception {
    UserLinkDTO link = getUserLinkDTO();
    MvcResult mvcResult = mvc.perform(post("/api/v1/user-management/users/links").contentType(APPLICATION_JSON).content(objectMapper.writeValueAsString(link))).andExpect(NO_ERROR_CODE).andExpect(OK_STATUS).andExpect(jsonPath("$.result.links").isNotEmpty()).andExpect(jsonPath("$.result.links").isArray()).andExpect(jsonPath("$.result.links", hasSize(1))).andReturn();
    JSONAssert.assertEquals(ADMIN_JSON_OBJECT, getGeneral(mvcResult), FALSE);
    JSONArray links = (JSONArray) getResultJSONObject(mvcResult).get("links");
    JSONAssert.assertEquals(USER_LINK, (JSONObject) links.get(0), FALSE);
}
Also used : UserLinkDTO(com.odysseusinc.arachne.portal.api.v1.dto.UserLinkDTO) JSONArray(org.json.JSONArray) MvcResult(org.springframework.test.web.servlet.MvcResult) ExpectedDatabase(com.github.springtestdbunit.annotation.ExpectedDatabase) Test(org.junit.Test) WithUserDetails(org.springframework.security.test.context.support.WithUserDetails) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup)

Example 4 with UserLinkDTO

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

the class BaseUserController method addLink.

@ApiOperation("Add link to user profile.")
@RequestMapping(value = "/api/v1/user-management/users/links", method = POST)
public JsonResult<UserProfileDTO> addLink(Principal principal, @Valid @RequestBody UserLinkDTO userLinkDTO, BindingResult binding) throws NotExistException, PermissionDeniedException, NotUniqueException {
    JsonResult<UserProfileDTO> result;
    if (binding.hasErrors()) {
        result = new JsonResult<>(VALIDATION_ERROR);
        for (FieldError fieldError : binding.getFieldErrors()) {
            result.getValidatorErrors().put(fieldError.getField(), fieldError.getDefaultMessage());
        }
    } else {
        U user = userService.getByEmail(principal.getName());
        user = userService.addLinkToUser(user.getId(), conversionService.convert(userLinkDTO, UserLink.class));
        UserProfileDTO userProfileDTO = conversionService.convert(user, UserProfileDTO.class);
        result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
        result.setResult(userProfileDTO);
    }
    return result;
}
Also used : UserProfileDTO(com.odysseusinc.arachne.portal.api.v1.dto.UserProfileDTO) FieldError(org.springframework.validation.FieldError) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with UserLinkDTO

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

the class UserControllerTests method getUserLinkDTO.

private UserLinkDTO getUserLinkDTO() {
    UserLinkDTO link = new UserLinkDTO();
    link.setDescription(USER_LINK_DESCRIPTION);
    link.setTitle(USER_LINK_TITLE);
    link.setUrl(USER_LINK_URL);
    return link;
}
Also used : UserLinkDTO(com.odysseusinc.arachne.portal.api.v1.dto.UserLinkDTO)

Aggregations

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