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;
}
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;
}
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);
}
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;
}
Aggregations