/* * (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(); } }
@Test @Ignore public void testContentRateAverage() { final User user1 = TestDomainHelper.createUser(1); final User user2 = TestDomainHelper.createUser(2); user1.setLanguage(english); user2.setLanguage(english); user1.setCountry(gb); user2.setCountry(gb); entityManager.persist(user1.getUserGroup()); entityManager.persist(user2.getUserGroup()); entityManager.persist(user1); entityManager.persist(user2); final Content cd = new Content(); cd.setLanguage(english); cd.setPublishedOn(new Date()); entityManager.persist(cd); entityManager.persist(new Rate(user1, cd, 1.3)); entityManager.persist(new Rate(user2, cd, 3.3)); // same user and content other rate final Rate rateFinded = rateFinder.find(user2, cd); rateFinded.setValue(4.3); entityManager.persist(rateFinded); closeTransaction(); final Double rate = rateFinder.calculateRate(cd); final Long rateByUsers = rateFinder.calculateRateNumberOfUsers(cd); final Double average = (1.3 + 4.3) / 2; assertEquals(average, rate); assertEquals(Long.valueOf(2), rateByUsers); final Rate newRate1 = rateFinder.find(user1, cd); final Rate newRate2 = rateFinder.find(user2, cd); assertEquals(new Double(1.3), newRate1.getValue()); assertEquals(new Double(4.3), newRate2.getValue()); }
/* * (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; }