use of org.sagebionetworks.repo.model.UserProfile in project Synapse-Repository-Services by Sage-Bionetworks.
the class UserProfileServiceImpl method updateUserProfile.
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
@Override
public UserProfile updateUserProfile(String userId, HttpHeaders header, String etag, HttpServletRequest request) throws NotFoundException, ConflictingUpdateException, DatastoreException, InvalidModelException, UnauthorizedException, IOException {
UserInfo userInfo = userManager.getUserInfo(userId);
UserProfile entity = (UserProfile) objectTypeSerializer.deserialize(request.getInputStream(), header, UserProfile.class, header.getContentType());
if (etag != null) {
entity.setEtag(etag.toString());
}
return userProfileManager.updateUserProfile(userInfo, entity);
}
use of org.sagebionetworks.repo.model.UserProfile in project Synapse-Repository-Services by Sage-Bionetworks.
the class DBOUserProfileDAOImpl method get.
@Override
public UserProfile get(String id, ObjectSchema schema) throws DatastoreException, NotFoundException {
MapSqlParameterSource param = new MapSqlParameterSource();
param.addValue(DBOUserProfile.OWNER_ID_FIELD_NAME, id);
DBOUserProfile jdo = basicDao.getObjectById(DBOUserProfile.class, param);
UserProfile dto = new UserProfile();
UserProfileUtils.copyDboToDto(jdo, dto, schema);
return dto;
}
use of org.sagebionetworks.repo.model.UserProfile in project Synapse-Repository-Services by Sage-Bionetworks.
the class DBOUserProfileDAOImpl method update.
/**
* @param fromBackup Whether we are updating from backup.
* Skip optimistic locking and accept the backup e-tag when restoring from backup.
*/
private UserProfile update(UserProfile dto, ObjectSchema schema, boolean fromBackup) throws DatastoreException, InvalidModelException, NotFoundException, ConflictingUpdateException {
DBOUserProfile dbo = null;
MapSqlParameterSource param = new MapSqlParameterSource();
param.addValue(DBOUserProfile.OWNER_ID_FIELD_NAME, dto.getOwnerId());
try {
dbo = simpleJdbcTemplate.queryForObject(SELECT_FOR_UPDATE_SQL, TABLE_MAPPING, param);
} catch (EmptyResultDataAccessException e) {
throw new NotFoundException("The resource you are attempting to access cannot be found");
}
if (!fromBackup) {
// if different rollback and throw a meaningful exception
if (!dbo.geteTag().equals(dto.getEtag())) {
throw new ConflictingUpdateException("Use profile was updated since you last fetched it, retrieve it again and reapply the update.");
}
}
UserProfileUtils.copyDtoToDbo(dto, dbo, schema);
if (!fromBackup) {
// Update with a new e-tag; otherwise, the backup e-tag is used implicitly
dbo.seteTag(eTagGenerator.generateETag(dbo));
}
boolean success = basicDao.update(dbo);
if (!success)
throw new DatastoreException("Unsuccessful updating user profile in database.");
UserProfile resultantDto = new UserProfile();
UserProfileUtils.copyDboToDto(dbo, resultantDto, schema);
return resultantDto;
}
use of org.sagebionetworks.repo.model.UserProfile in project Synapse-Repository-Services by Sage-Bionetworks.
the class UserManagerImpl method getDisplayName.
/**
* @param principalId
* @return for a group, returns the group name, for a user returns the display name in the user's profile
*/
@Override
public String getDisplayName(Long principalId) throws NotFoundException, DatastoreException {
UserGroup userGroup = userGroupDAO.get(principalId.toString());
if (userGroup.getIsIndividual()) {
ObjectSchema schema = SchemaCache.getSchema(UserProfile.class);
UserProfile userProfile = userProfileDAO.get(principalId.toString(), schema);
return userProfile.getDisplayName();
} else {
return userGroup.getName();
}
}
use of org.sagebionetworks.repo.model.UserProfile in project Synapse-Repository-Services by Sage-Bionetworks.
the class UserProfileManagerImpl method updateUserProfile.
/**
* This method is only available to the object owner or an admin
*/
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
@Override
public UserProfile updateUserProfile(UserInfo userInfo, UserProfile updated) throws NotFoundException, DatastoreException, UnauthorizedException, ConflictingUpdateException, InvalidModelException {
ObjectSchema schema = SchemaCache.getSchema(UserProfile.class);
UserProfile userProfile = userProfileDAO.get(updated.getOwnerId(), schema);
boolean canUpdate = UserProfileManagerUtils.isOwnerOrAdmin(userInfo, userProfile.getOwnerId());
if (!canUpdate)
throw new UnauthorizedException("Only owner or administrator may update UserProfile.");
attachmentManager.checkAttachmentsForPreviews(updated);
return userProfileDAO.update(updated, schema);
}
Aggregations