Example #1
0
  @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);
    }
  }
Example #2
0
 @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);
   }
 }
Example #3
0
  @Override
  public SimplePopup getPopup() {
    T feature = this.getFeature();

    Map<? extends Field, ? extends Object> attr = feature.getAttributes();
    Map<String, String> attrString = new LinkedHashMap<>();
    for (Field key : attr.keySet()) attrString.put(key.getName(), attr.get(key).toString());

    return new SimplePopup(feature.toString(), attrString);
  }
 @Override
 public double calculateLoss(Classifier predictiveModel, List<T> validationSet) {
   List<ClassifierInstance> singleTargetValidationSet = Lists.newArrayList();
   for (T instance : validationSet) {
     singleTargetValidationSet.add(
         new ClassifierInstance(
             instance.getAttributes(),
             instanceTargetSelector.getSingleLabel(instance),
             instance.getWeight()));
   }
   return lossFunction.getLoss(
       Utils.calcResultPredictions(predictiveModel, singleTargetValidationSet));
 }