public static Organization addSite(Organization organization) throws Exception {

    return OrganizationLocalServiceUtil.updateOrganization(
        organization.getCompanyId(),
        organization.getOrganizationId(),
        organization.getParentOrganizationId(),
        organization.getName(),
        organization.getType(),
        organization.getRegionId(),
        organization.getCountryId(),
        organization.getStatusId(),
        organization.getComments(),
        false,
        null,
        true,
        null);
  }
Esempio n. 2
0
 public List<TtUser> getUsersForRole(String roleName, long userId) {
   List<TtUser> roleUsrs = new ArrayList<TtUser>();
   try {
     List<Organization> usrOrgs = orgService.getUserOrganizations(userId);
     for (Organization org : usrOrgs) {
       Role role = roleService.getRole(org.getCompanyId(), roleName);
       if (role != null) {
         List<User> usrs = usrService.getRoleUsers(role.getRoleId());
         for (User usr : usrs) {
           roleUsrs.add(UserServiceConversionHelper.convertPortalUserToTtUser(usr));
         }
       }
     }
   } catch (PortalException ex) {
     Logger.getLogger(UserServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
   } catch (SystemException ex) {
     Logger.getLogger(UserServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
   }
   return roleUsrs;
 }
  private String getUserScreenName(List<Organization> organizations)
      throws SystemException, PortalException {

    debug("Getting next userScreenName for deviceUser in organizations: " + organizations);

    if (organizations == null || organizations.size() != 1) {
      throw new IllegalArgumentException(
          "Doctor must belong to EXACTLY 1 organization but "
              + (organizations != null ? organizations.size() : 0)
              + " were found!");
    }

    Organization organization = organizations.get(0);
    String countryCode =
        PrimumUtilLocalServiceUtil.getExpandoValue(
                organization.getCompanyId(),
                Organization.class.getName(),
                PrimumConstantsLocalServiceUtil.getOrganizationExpandoFieldCountryCode(),
                organization.getOrganizationId())
            .getString();

    debug("countryCode: " + countryCode);
    String organizationCode =
        PrimumUtilLocalServiceUtil.getExpandoValue(
                organization.getCompanyId(),
                Organization.class.getName(),
                PrimumConstantsLocalServiceUtil.getOrganizationExpandoFieldOrganizationCode(),
                organization.getOrganizationId())
            .getString();
    debug("organizationCode: " + organizationCode);

    List<User> groupUsers =
        UserLocalServiceUtil.getOrganizationUsers(organization.getOrganizationId());

    debug((groupUsers != null ? groupUsers.size() : 0) + " users in organizacion");

    Role role =
        RoleLocalServiceUtil.fetchRole(
            organization.getCompanyId(), PrimumConstantsLocalServiceUtil.getPrimumRole_DEVICE());

    int maxSeqNum = 0;
    for (User user : groupUsers) {
      if (RoleLocalServiceUtil.hasUserRole(user.getUserId(), role.getRoleId())) {
        // 8429999000068
        String screenName = user.getScreenName();
        debug("checking userScreenName: " + screenName);
        if (screenName.length() == 13) {
          int hisNum = Integer.valueOf(user.getScreenName().substring(7, 12));
          debug("user number is: " + hisNum);
          if (hisNum > maxSeqNum) {
            maxSeqNum = hisNum;
            debug("maxSeqNum updated to: " + maxSeqNum);
          }
        }
      }
    }

    String userScreenName = countryCode + organizationCode + String.format("%05d", maxSeqNum + 1);

    debug("userScreenName is: " + userScreenName);
    return userScreenName + String.valueOf(EAN13.generateValidateDigit(userScreenName));
  }