Beispiel #1
0
 /*
  * (non-Javadoc)
  *
  * @see cc.kune.core.server.manager.GroupManager#update(java.lang.Long,
  * cc.kune.core.shared.dto.GroupDTO)
  */
 @Override
 public Group update(final Long groupId, final GroupDTO groupDTO) {
   final Group group = find(groupId);
   final String shortName = groupDTO.getShortName();
   final String longName = groupDTO.getLongName();
   if (!longName.equals(group.getLongName())) {
     checkIfLongNameAreInUse(longName);
     group.setLongName(longName);
   }
   if (!shortName.equals(group.getShortName())) {
     checkIfShortNameAreInUse(shortName);
     final String oldDir =
         kuneProperties.get(KuneProperties.UPLOAD_LOCATION)
             + FileUtils.groupToDir(group.getShortName());
     final String newDir =
         kuneProperties.get(KuneProperties.UPLOAD_LOCATION) + FileUtils.groupToDir(shortName);
     if (fileManager.exists(oldDir)) {
       if (fileManager.exists(newDir)) {
         throw new DefaultException("Destination group directory exists");
       }
       fileManager.mv(oldDir, newDir);
     }
     group.setShortName(shortName);
   }
   group.setGroupType(groupDTO.getGroupType());
   setAdmissionType(group);
   final boolean isClosed = group.getGroupType().equals(GroupType.CLOSED);
   setSocialNetwork(group, getDefGroupMode(isClosed), getDefSNVisibility(isClosed));
   persist(group);
   snCache.expire(group);
   return group;
 }
 /**
  * Instantiates a new notification sender default.
  *
  * @param mailService the mail service
  * @param waveService the wave service
  * @param xmppManager the xmpp manager
  * @param i18n the i18n
  * @param usersOnline the users online
  * @param kuneProperties the kune properties
  * @throws IOException Signals that an I/O exception has occurred.
  */
 @Inject
 public NotificationSenderDefault(
     final MailService mailService,
     final KuneWaveService waveService,
     final XmppManager xmppManager,
     final I18nTranslationServiceMultiLang i18n,
     final UsersOnline usersOnline,
     final KuneProperties kuneProperties)
     throws IOException {
   this.mailService = mailService;
   this.waveService = waveService;
   this.xmppManager = xmppManager;
   this.i18n = i18n;
   this.usersOnline = usersOnline;
   emailTemplate =
       FileUtils.readFileToString(
           new File(kuneProperties.get(KuneProperties.SITE_EMAIL_TEMPLATE)));
   Preconditions.checkNotNull(emailTemplate);
   Preconditions.checkArgument(TextUtils.notEmpty(emailTemplate));
   siteName = kuneProperties.get(KuneProperties.SITE_NAME);
 }
Beispiel #3
0
  /*
   * (non-Javadoc)
   *
   * @see
   * cc.kune.core.server.manager.GroupManager#createUserGroup(cc.kune.domain
   * .User, boolean)
   */
  @Override
  public Group createUserGroup(final User user, final boolean wantPersonalHomepage)
      throws GroupShortNameInUseException, EmailAddressInUseException {
    final String defaultSiteWorkspaceTheme = kuneProperties.get(KuneProperties.WS_THEMES_DEF);
    final License licenseDef = licenseManager.getDefLicense();
    final Group userGroup =
        new Group(user.getShortName(), user.getName(), licenseDef, GroupType.PERSONAL);
    User userSameEmail = null;
    try {
      userSameEmail = userFinder.findByEmail(user.getEmail());
    } catch (final NoResultException e) {
      // Ok, no more with this email
    }
    if (userSameEmail != null) {
      throw new EmailAddressInUseException();
    }
    userGroup.setAdmissionType(AdmissionType.Closed);
    userGroup.setWorkspaceTheme(defaultSiteWorkspaceTheme);
    userGroup.setDefaultContent(null);
    user.setUserGroup(userGroup);
    initSocialNetwork(userGroup, userGroup, GroupListMode.EVERYONE, SocialNetworkVisibility.anyone);

    final String title = i18n.t("[%s] Bio", user.getName());
    final String body = i18n.t("This is [%s]'s bio, currently empty", user.getName());
    try {
      initGroup(
          user,
          userGroup,
          wantPersonalHomepage
              ? serverToolRegistry.getToolsRegisEnabledForUsers()
              : ServerToolRegistry.emptyToolList,
          title,
          body);
      super.persist(user, User.class);
    } catch (final PersistenceException e) {
      if (e.getCause() instanceof ConstraintViolationException) {
        throw new GroupShortNameInUseException();
      }
      throw e;
    }
    return userGroup;
  }
Beispiel #4
0
 /*
  * (non-Javadoc)
  *
  * @see
  * cc.kune.core.server.manager.GroupManager#createGroup(cc.kune.domain.Group,
  * cc.kune.domain.User, java.lang.String)
  */
 @Override
 public Group createGroup(final Group group, final User user, final String publicDescrip)
     throws GroupShortNameInUseException, GroupLongNameInUseException, UserMustBeLoggedException {
   checkIfShortNameAreInUse(group.getShortName());
   checkIfLongNameAreInUse(group.getLongName());
   final String defaultSiteWorkspaceTheme = kuneProperties.get(KuneProperties.WS_THEMES_DEF);
   if (User.isKnownUser(user)) {
     setAdmissionType(group);
     final String licName = group.getDefaultLicense().getShortName();
     final License license = licenseFinder.findByShortName(licName);
     group.setDefaultLicense(license);
     group.setWorkspaceTheme(defaultSiteWorkspaceTheme);
     final boolean isClosed = group.getGroupType().equals(GroupType.CLOSED);
     initSocialNetwork(
         group, user.getUserGroup(), getDefGroupMode(isClosed), getDefSNVisibility(isClosed));
     final String title = i18n.t("About [%s]", group.getLongName());
     initGroup(
         user, group, serverToolRegistry.getToolsRegisEnabledForGroups(), title, publicDescrip);
     snCache.expire(user.getUserGroup());
     return group;
   } else {
     throw new UserMustBeLoggedException();
   }
 }
  @Override
  @SuppressWarnings({"rawtypes"})
  protected void doPost(final HttpServletRequest req, final HttpServletResponse response)
      throws ServletException, IOException {

    beforePostStart();

    final DiskFileItemFactory factory = new DiskFileItemFactory();
    // maximum size that will be stored in memory
    factory.setSizeThreshold(4096);
    // the location for saving data that is larger than getSizeThreshold()
    factory.setRepository(new File("/tmp"));

    if (!ServletFileUpload.isMultipartContent(req)) {
      LOG.warn("Not a multipart upload");
    }

    final ServletFileUpload upload = new ServletFileUpload(factory);
    // maximum size before a FileUploadException will be thrown
    upload.setSizeMax(kuneProperties.getLong(KuneProperties.UPLOAD_MAX_FILE_SIZE) * 1024 * 1024);

    try {
      final List fileItems = upload.parseRequest(req);
      String userHash = null;
      StateToken stateToken = null;
      String typeId = null;
      String fileName = null;
      FileItem file = null;
      for (final Iterator iterator = fileItems.iterator(); iterator.hasNext(); ) {
        final FileItem item = (FileItem) iterator.next();
        if (item.isFormField()) {
          final String name = item.getFieldName();
          final String value = item.getString();
          LOG.info("name: " + name + " value: " + value);
          if (name.equals(FileConstants.HASH)) {
            userHash = value;
          }
          if (name.equals(FileConstants.TOKEN)) {
            stateToken = new StateToken(value);
          }
          if (name.equals(FileConstants.TYPE_ID)) {
            typeId = value;
          }
        } else {
          fileName = item.getName();
          LOG.info(
              "file: "
                  + fileName
                  + " fieldName: "
                  + item.getFieldName()
                  + " size: "
                  + item.getSize()
                  + " typeId: "
                  + typeId);
          file = item;
        }
      }
      createUploadedFile(userHash, stateToken, fileName, file, typeId);
      onSuccess(response);
    } catch (final FileUploadException e) {
      onFileUploadException(response);
    } catch (final Exception e) {
      onOtherException(response, e);
    }
  }