Пример #1
0
  /** {@inheritDoc} */
  public void createMembership(Membership m, boolean broadcast) throws Exception {
    if (orgService.getMembershipTypeHandler().findMembershipType(m.getMembershipType()) == null) {
      throw new InvalidNameException(
          "Can not create membership record "
              + m.getId()
              + ", because membership"
              + "type "
              + m.getMembershipType()
              + " does not exist.");
    }

    if (orgService.getGroupHandler().findGroupById(m.getGroupId()) == null) {
      throw new InvalidNameException(
          "Can not create membership record "
              + m.getId()
              + ", because group "
              + m.getGroupId()
              + " does not exist.");
    }

    if (orgService.getUserHandler().findUserByName(m.getUserName()) == null) {
      throw new InvalidNameException(
          "Can not create membership record "
              + m.getId()
              + ", because user "
              + m.getGroupId()
              + " does not exist.");
    }

    // check if we already have membership record
    if (findMembershipByUserGroupAndType(m.getUserName(), m.getGroupId(), m.getMembershipType())
        != null) {
      return;
    }

    if (broadcast) {
      preSave(m, true);
    }

    Session session = service_.openSession();
    session.save(m);
    session.flush();

    if (broadcast) {
      postSave(m, true);
    }
  }
Пример #2
0
 private MembershipUser toMembershipUser(Membership membership) throws Exception {
   OrganizationService service = getApplicationComponent(OrganizationService.class);
   String userName = membership.getUserName();
   UserHandler handler = service.getUserHandler();
   User user = handler.findUserByName(userName);
   if (user == null) return null;
   return new MembershipUser(user, membership.getMembershipType(), membership.getId());
 }
Пример #3
0
 public void write(OutputStream out) throws IOException {
   try {
     XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
     outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
     XMLStreamWriter xsw = outputFactory.createXMLStreamWriter(out);
     xsw.writeStartDocument();
     xsw.writeStartElement("membership");
     xsw.writeDefaultNamespace(XMLContants.EXO_NAMESPACE_URL);
     xsw.writeNamespace(XMLContants.XLINK_PREFIX, XMLContants.XLINK_NAMESPACE_URL);
     xsw.writeAttribute(
         XMLContants.XLINK_NAMESPACE_URL,
         XMLContants.XLINK_HREF,
         baseURI_
             + "/organization/membership/"
             + membership_.getId()
             + "/?output=xml&command=view");
     xsw.writeStartElement("id");
     xsw.writeCharacters(membership_.getId());
     xsw.writeEndElement();
     xsw.writeStartElement("group-id");
     xsw.writeCharacters(membership_.getGroupId());
     xsw.writeEndElement();
     xsw.writeStartElement("user-name");
     xsw.writeCharacters(membership_.getUserName());
     xsw.writeEndElement();
     xsw.writeStartElement("membership-type");
     xsw.writeCharacters(membership_.getMembershipType());
     xsw.writeEndElement();
     xsw.writeEndDocument();
     xsw.flush();
     xsw.close();
   } catch (Exception e) {
     e.printStackTrace();
     throw new IOException(e.getMessage());
   }
 }