@Override @HasPermission(action = UGC_UPDATE, type = SocialPermission.class) public void setAttributes( @SecuredObject final String ugcId, final String contextId, final Map attributes) throws SocialException, UGCNotFound { log.debug("logging.ugc.addingAttributes", attributes, ugcId, contextId); try { T toUpdate = (T) ugcRepository.findUGC(contextId, ugcId); if (toUpdate == null) { throw new UGCNotFound("Unable to found ugc with id " + ugcId); } final Map attrs = toUpdate.getAttributes(); attrs.putAll(attrs); ugcRepository.setAttributes(ugcId, contextId, attrs); final SocialEvent<T> event = new SocialEvent<T>( ugcId, attributes, SocialSecurityUtils.getCurrentProfile().getId().toString(), UGCEvent.UPDATE_ATTRIBUTES); event.setAttribute("baseUrl", calculateBaseUrl()); reactor.notify(UGCEvent.UPDATE_ATTRIBUTES.getName(), Event.wrap(event)); } catch (MongoDataException ex) { log.debug("logging.ugc.unableToAddAttrs", ex, attributes, ugcId, contextId); throw new UGCException("Unable to add Attributes to UGC", ex); } }
public void removeWatcher(final String profileId, final String frequency) { if (watchers.remove(new ProfileWatchOptions(profileId, frequency))) { log.debug("logging.system.notification.userRemoveWatching", profileId, threadId, frequency); } else { log.debug("logging.system.notification.userUnableToRemove", profileId, threadId, frequency); } }
public void addWatcher(final String profileId, final String frequency) { final ProfileWatchOptions toAdd = new ProfileWatchOptions(profileId, frequency); if (!watchers.contains(toAdd)) { watchers.add(toAdd); log.debug("logging.system.notification.userAddedWatching", profileId, threadId, frequency); } else { log.debug("logging.system.notification.userAlreadyWatching", profileId, threadId, frequency); } }
@Override @HasPermission(action = UGC_UPDATE, type = SocialPermission.class) public UGC update( @SecuredObject final String ugcId, final String body, final String subject, final String contextId, final Map attributes) throws SocialException, UGCNotFound { log.debug("logging.ugc.updateUgc", ugcId); try { final Profile currentProfile = SocialSecurityUtils.getCurrentProfile(); boolean moderateByMail = Boolean.parseBoolean( tenantConfigurationService.getProperty(contextId, "moderateByMailEnable").toString()); if (!ObjectId.isValid(ugcId)) { throw new IllegalArgumentException("Given UGC Id is not valid"); } T toUpdate = (T) ugcRepository.findUGC(contextId, ugcId); if (toUpdate == null) { throw new IllegalArgumentException("UGC with Id " + ugcId + " does not exists"); } if (StringUtils.isNotBlank(body)) { toUpdate.setBody(body); } if (StringUtils.isNotBlank(subject)) { toUpdate.setBody(subject); } pipeline.processUgc(toUpdate); if (moderateByMail && !SocialSecurityUtils.isProfileModeratorOrAdmin(currentProfile, contextId)) { if (toUpdate instanceof SocialUgc) { ((SocialUgc) toUpdate).setModerationStatus(ModerationStatus.UNMODERATED); } } ugcRepository.update(ugcId, toUpdate, false, false); final SocialEvent<T> event = new SocialEvent<>( toUpdate, SocialSecurityUtils.getCurrentProfile().getId().toString(), UGCEvent.UPDATE); event.setAttribute("baseUrl", calculateBaseUrl()); reactor.notify(UGCEvent.UPDATE.getName(), Event.wrap(event)); if (attributes != null && !attributes.isEmpty()) { toUpdate.getAttributes().putAll(attributes); // ToDo This should be one query, problem is with deep attributes !! setAttributes(toUpdate.getId().toString(), contextId, toUpdate.getAttributes()); reactor.notify(UGCEvent.UPDATE_ATTRIBUTES, Event.wrap(attributes)); } log.info("logging.ugc.updatedUgc", ugcId); return toUpdate; } catch (MongoDataException ex) { log.error("logging.ugc.unableToUpdateUgc", ex); throw new UGCException("Unable to removeWatcher UGC", ex); } }
@Override @HasPermission(action = UGC_CREATE, type = SocialPermission.class) public UGC create( final String contextId, final String ugcParentId, final String targetId, final String textContent, final String subject, final Map attrs, final boolean isAnonymous) throws SocialException { log.debug("logging.ugc.creatingUgc", contextId, targetId, ugcParentId, subject, attrs); final UGC template = new UGC(subject, textContent, targetId); template.setAnonymousFlag(isAnonymous); T newUgc = (T) ugcFactory.newInstance(template); newUgc.setAttributes(attrs); try { if (ObjectId.isValid(ugcParentId)) { setupAncestors(newUgc, ugcParentId, contextId); } else { log.debug("logging.ugc.invalidParentId"); } if (StringUtils.isBlank(contextId)) { throw new IllegalArgumentException("context cannot be null"); } pipeline.processUgc(newUgc); ugcRepository.save(newUgc); final SocialEvent<T> event = new SocialEvent<>( newUgc, SocialSecurityUtils.getCurrentProfile().getId().toString(), UGCEvent.CREATE); event.setAttribute("baseUrl", calculateBaseUrl()); reactor.notify(UGCEvent.CREATE.getName(), Event.wrap(event)); setupAutoWatch(targetId, SocialSecurityUtils.getCurrentProfile(), contextId); log.info("logging.ugc.created", newUgc); return newUgc; } catch (MongoDataException ex) { log.error("logging.ugc.errorSaving", ex); throw new UGCException("Unable to Save UGC"); } }
@Override @HasPermission(action = UGC_UPDATE, type = SocialPermission.class) public void deleteAttribute( @SecuredObject final String ugcId, final String[] attributesName, final String contextId) throws SocialException { log.debug("logging.ugc.deleteAttributes", attributesName, ugcId); try { ugcRepository.deleteAttribute(ugcId, contextId, attributesName); final SocialEvent<T> event = new SocialEvent<T>( ugcId, SocialSecurityUtils.getCurrentProfile().getId().toString(), UGCEvent.DELETE_ATTRIBUTES); event.setAttribute("baseUrl", calculateBaseUrl()); reactor.notify(UGCEvent.DELETE_ATTRIBUTES.getName(), Event.wrap(event)); } catch (MongoDataException ex) { log.debug("logging.ugc.unableToDelAttrs", ex, attributesName, ugcId); throw new UGCException("Unable to delete attribute for ugc", ex); } }
@Override @HasPermission(action = UGC_READ, type = SocialPermission.class) public Iterable<T> readByTargetId(final String targetId, final String contextId) throws UGCException { log.debug("logging.ugc.findingByTarget", targetId, contextId); try { return buildUgcTreeList( IterableUtils.toList(ugcRepository.findByTargetId(targetId, contextId)), Integer.MAX_VALUE); } catch (MongoDataException ex) { log.error("logging.ugc.unableRead", ex); throw new UGCException("Unable to ", ex); } }
private void setupAutoWatch( final String targetId, final Profile currentProfile, final String context) throws NotificationException { final Map<String, Object> profileMap = currentProfile.getAttributes(); if (profileMap.containsKey("defaultFrequency") && profileMap.containsKey("autoWatch")) { boolean autoWatch = currentProfile.getAttribute("autoWatch"); if (autoWatch) { notificationService.subscribeUser( currentProfile, context + "/" + targetId, (String) currentProfile.getAttribute("defaultFrequency")); } } else { log.debug("Profile don't have set either defaultFrequency or autoWatch attributes"); } }
@Override @HasPermission(action = UGC_DELETE, type = SocialPermission.class) public boolean deleteUgc(final String ugcId, final String contextId) throws SocialException { log.debug("logging.ugc.deleteUgc", ugcId); try { ugcRepository.deleteUgc(ugcId, contextId); final SocialEvent<T> event = new SocialEvent<T>( ugcId, SocialSecurityUtils.getCurrentProfile().getId().toString(), UGCEvent.DELETE); event.setAttribute("baseUrl", calculateBaseUrl()); reactor.notify(UGCEvent.DELETE.getName(), Event.wrap(event)); } catch (MongoDataException ex) { log.error("logging.ugc.deleteUgcError", ex, ugcId, contextId); throw new UGCException("Unable to delete UGC", ex); } return false; }
@Override @HasPermission(action = UGC_READ, type = SocialPermission.class) public List<T> readChildren( final String ugcId, final String targetId, final String contextId, final int start, final int limit, final List sortOrder, final int upToLevel, final int childrenPerLevel) throws UGCException, UGCNotFound { log.debug("logging.ugc.readChildren", ugcId, contextId, limit, start); try { return buildUgcTreeList( IterableUtils.toList( ugcRepository.findChildren( ugcId, targetId, contextId, start, limit, sortOrder, upToLevel)), childrenPerLevel); } catch (MongoDataException ex) { log.error("logging.ugc.unableToRead", ex); throw new UGCException("Unable to ", ex); } }
@Override @HasPermission(action = UGC_READ, type = SocialPermission.class) public Iterable<T> search( final String contextId, final String query, final String sort, final int start, final int limit) throws UGCException { log.debug( "Finding all ugc of context {} with user query {} sorted by {} skipping {} and with a limit of {}", contextId, query, sort, start, limit); isQueryValid(query); try { return ugcRepository.findByUserQuery(contextId, query, sort, start, limit); } catch (MongoDataException ex) { log.error("Unable to find User with given query" + query + " sorted by " + sort, ex); throw new UGCException("Unable to find Ugc with user query ", ex); } }