Search in sources :

Example 1 with UserPublicationDTO

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

the class UserPublicationToUserPublicationDTOConverter method convert.

@Override
public UserPublicationDTO convert(UserPublication publication) {
    UserPublicationDTO dto = new UserPublicationDTO();
    dto.setId(publication.getId());
    dto.setTitle(publication.getTitle());
    dto.setDescription(publication.getDescription());
    dto.setDate(publication.getDate());
    dto.setPublisher(publication.getPublisher());
    dto.setUrl(publication.getUrl());
    return dto;
}
Also used : UserPublicationDTO(com.odysseusinc.arachne.portal.api.v1.dto.UserPublicationDTO)

Example 2 with UserPublicationDTO

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

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

the class UserControllerTests method testAddPublicationToUser.

@Test
@WithUserDetails(value = ADMIN_EMAIL)
@DatabaseSetup("/data/user/admin-user.xml")
@ExpectedDatabase(value = "/data/user/admin-user-with-publication.xml", assertionMode = NON_STRICT)
public void testAddPublicationToUser() throws Exception {
    UserPublicationDTO inputDTO = new UserPublicationDTO();
    inputDTO.setDescription(USER_LINK_DESCRIPTION);
    inputDTO.setTitle(USER_LINK_TITLE);
    inputDTO.setUrl(USER_LINK_URL);
    inputDTO.setDate(DATE);
    inputDTO.setPublisher(PUBLISHER);
    MvcResult mvcResult = mvc.perform(post("/api/v1/user-management/users/publications").contentType(APPLICATION_JSON).content(objectMapper.writeValueAsString(inputDTO))).andExpect(NO_ERROR_CODE).andExpect(OK_STATUS).andExpect(jsonPath("$.result.publications").isNotEmpty()).andExpect(jsonPath("$.result.publications", hasSize(1))).andReturn();
    JSONAssert.assertEquals(ADMIN_JSON_OBJECT, getGeneral(mvcResult), FALSE);
    JSONArray publications = (JSONArray) getResultJSONObject(mvcResult).get("publications");
    JSONAssert.assertEquals(PUBLICATION, (JSONObject) publications.get(0), FALSE);
}
Also used : JSONArray(org.json.JSONArray) UserPublicationDTO(com.odysseusinc.arachne.portal.api.v1.dto.UserPublicationDTO) 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 UserPublicationDTO

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

the class BaseUserController method addPublication.

@ApiOperation("Add user's publication.")
@RequestMapping(value = "/api/v1/user-management/users/publications", method = POST)
public JsonResult<UserProfileDTO> addPublication(Principal principal, @Valid @RequestBody UserPublicationDTO userPublicationDTO, 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.addPublicationToUser(user.getId(), conversionService.convert(userPublicationDTO, UserPublication.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)

Aggregations

UserPublicationDTO (com.odysseusinc.arachne.portal.api.v1.dto.UserPublicationDTO)3 UserProfileDTO (com.odysseusinc.arachne.portal.api.v1.dto.UserProfileDTO)2 DatabaseSetup (com.github.springtestdbunit.annotation.DatabaseSetup)1 ExpectedDatabase (com.github.springtestdbunit.annotation.ExpectedDatabase)1 UserLinkDTO (com.odysseusinc.arachne.portal.api.v1.dto.UserLinkDTO)1 UserProfileGeneralDTO (com.odysseusinc.arachne.portal.api.v1.dto.UserProfileGeneralDTO)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