use of com.pratilipi.common.exception.InsufficientAccessException in project pratilipi by Pratilipi.
the class AuthorDataUtil method saveAuthorData.
public static AuthorData saveAuthorData(AuthorData authorData) throws InvalidArgumentException, InsufficientAccessException, UnexpectedServerException {
_validateAuthorDataForSave(authorData);
boolean isNew = authorData.getId() == null;
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
Author author = isNew ? dataAccessor.newAuthor() : dataAccessor.getAuthor(authorData.getId());
if (isNew && !hasAccessToAddAuthorData(authorData))
throw new InsufficientAccessException();
if (!isNew && !hasAccessToUpdateAuthorData(author, authorData))
throw new InsufficientAccessException();
AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), isNew ? AccessType.AUTHOR_ADD : AccessType.AUTHOR_UPDATE, author);
if (authorData.hasFirstName())
author.setFirstName(authorData.getFirstName());
if (authorData.hasLastName())
author.setLastName(authorData.getLastName());
if (authorData.hasPenName())
author.setPenName(authorData.getPenName());
if (authorData.hasFirstNameEn())
author.setFirstNameEn(authorData.getFirstNameEn());
if (authorData.hasLastNameEn())
author.setLastNameEn(authorData.getLastNameEn());
if (authorData.hasPenNameEn())
author.setPenNameEn(authorData.getPenNameEn());
if (authorData.hasGender())
author.setGender(authorData.getGender());
if (authorData.hasDateOfBirth())
author.setDateOfBirth(authorData.getDateOfBirth());
if (authorData.hasLanguage())
author.setLanguage(authorData.getLanguage());
if (authorData.hasLocation())
author.setLocation(authorData.getLocation());
if (authorData.hasSummary())
author.setSummary(authorData.getSummary());
if (authorData.hasState())
author.setState(authorData.getState());
if (isNew)
author.setRegistrationDate(new Date());
author.setLastUpdated(new Date());
author = dataAccessor.createOrUpdateAuthor(author, auditLog);
if (isNew)
createOrUpdateAuthorPageUrl(author.getId());
return createAuthorData(author);
}
use of com.pratilipi.common.exception.InsufficientAccessException in project pratilipi by Pratilipi.
the class TagsApi method addTags.
@Post
public GenericResponse addTags(PostRequest request) throws InsufficientAccessException {
// Security Hack
AccessToken accessToken = AccessTokenFilter.getAccessToken();
if (accessToken.getUserId() != 5073076857339904L) {
Logger.getLogger(TagsApi.class.getSimpleName()).log(Level.SEVERE, "AccessToken : " + accessToken.getId());
Logger.getLogger(TagsApi.class.getSimpleName()).log(Level.SEVERE, "User Id : " + accessToken.getUserId());
throw new InsufficientAccessException();
}
Gson gson = new Gson();
// Creating TagData object.
TagData tagData = gson.fromJson(gson.toJson(request), TagData.class);
tagData = TagDataUtil.saveTag(tagData);
return new GenericResponse();
}
use of com.pratilipi.common.exception.InsufficientAccessException in project pratilipi by Pratilipi.
the class UserV2Api method get.
@Get
public Response get(GetRequest request) throws InsufficientAccessException {
if (request.userId == null || request.userId.equals(UserDataUtil.getCurrentUser().getId()))
return new Response(UserDataUtil.getCurrentUser(), UserV2Api.class);
if (!UserAccessUtil.hasUserAccess(UserDataUtil.getCurrentUser().getId(), UxModeFilter.getWebsite().getFilterLanguage(), AccessType.AUTHOR_ADD))
throw new InsufficientAccessException();
UserData userData = UserDataUtil.createUserData(DataAccessorFactory.getDataAccessor().getUser(request.userId), null);
userData.setAuthor(new AuthorData());
return new Response(userData, UserV2Api.class);
}
Aggregations