コード例 #1
0
 /**
  * Creates a new <code>documents.document_alias</code> resource instance.
  *
  * @param session the CoralSession
  * @param name the name of the new resource
  * @param parent the parent resource.
  * @param originalDocument the originalDocument attribute
  * @param preferences the preferences attribute
  * @param site the site attribute
  * @param title the title attribute
  * @return a new DocumentAliasResource instance.
  * @throws ValueRequiredException if one of the required attribues is undefined.
  * @throws InvalidResourceNameException if the name argument contains illegal characters.
  */
 public static DocumentAliasResource createDocumentAliasResource(
     CoralSession session,
     String name,
     Resource parent,
     DocumentNodeResource originalDocument,
     Parameters preferences,
     SiteResource site,
     String title)
     throws ValueRequiredException, InvalidResourceNameException {
   try {
     ResourceClass<DocumentAliasResource> rc =
         session
             .getSchema()
             .getResourceClass("documents.document_alias", DocumentAliasResource.class);
     Map<AttributeDefinition<?>, Object> attrs = new HashMap<AttributeDefinition<?>, Object>();
     attrs.put(rc.getAttribute("originalDocument"), originalDocument);
     attrs.put(rc.getAttribute("preferences"), preferences);
     attrs.put(rc.getAttribute("site"), site);
     attrs.put(rc.getAttribute("title"), title);
     Resource res = session.getStore().createResource(name, parent, rc, attrs);
     if (!(res instanceof DocumentAliasResource)) {
       throw new BackendException(
           "incosistent schema: created object is " + res.getClass().getName());
     }
     return (DocumentAliasResource) res;
   } catch (EntityDoesNotExistException e) {
     throw new BackendException("incompatible schema change", e);
   }
 }
コード例 #2
0
 /**
  * Creates a new <code>cms.confirmation.email_confirmation_request</code> resource instance.
  *
  * @param session the CoralSession
  * @param name the name of the new resource
  * @param parent the parent resource.
  * @param email the email attribute
  * @return a new EmailConfirmationRequestResource instance.
  * @throws ValueRequiredException if one of the required attribues is undefined.
  * @throws InvalidResourceNameException if the name argument contains illegal characters.
  */
 public static EmailConfirmationRequestResource createEmailConfirmationRequestResource(
     CoralSession session, String name, Resource parent, String email)
     throws ValueRequiredException, InvalidResourceNameException {
   try {
     ResourceClass<EmailConfirmationRequestResource> rc =
         session
             .getSchema()
             .getResourceClass(
                 "cms.confirmation.email_confirmation_request",
                 EmailConfirmationRequestResource.class);
     Map<AttributeDefinition<?>, Object> attrs = new HashMap<AttributeDefinition<?>, Object>();
     attrs.put(rc.getAttribute("email"), email);
     Resource res = session.getStore().createResource(name, parent, rc, attrs);
     if (!(res instanceof EmailConfirmationRequestResource)) {
       throw new BackendException(
           "incosistent schema: created object is " + res.getClass().getName());
     }
     return (EmailConfirmationRequestResource) res;
   } catch (EntityDoesNotExistException e) {
     throw new BackendException("incompatible schema change", e);
   }
 }
コード例 #3
0
  protected void fixture(
      Implementation firstImpl, Implementation secondImpl, Implementation thirdImpl)
      throws Exception {
    CoralSchema schema = coral.getSchema();
    AttributeClass<String> stringAttr = schema.getAttributeClass("string", String.class);
    AttributeClass<Integer> intAttr = schema.getAttributeClass("integer", Integer.class);
    AttributeClass<Resource> resourceAttr = schema.getAttributeClass("resource", Resource.class);

    CoralStore store = coral.getStore();
    Resource rootRes = store.getResource(CoralStore.ROOT_RESOURCE);
    Map<AttributeDefinition<?>, Object> attributes = new HashMap<AttributeDefinition<?>, Object>();

    ResourceClass<?> firstClass;
    AttributeDefinition<String> a1;
    AttributeDefinition<Integer> a2;
    AttributeDefinition<Resource> a3;

    firstClass =
        schema.createResourceClass(
            "first",
            firstImpl.getResClass().getName(),
            firstImpl.getHandlerClass().getName(),
            firstImpl == Implementation.TABULAR ? "first" : null,
            0);
    a1 = schema.createAttribute("a1", stringAttr, "a1_", null, 0);
    schema.addAttribute(firstClass, a1, null);
    a2 = schema.createAttribute("a2", intAttr, null, null, 0);
    schema.addAttribute(firstClass, a2, 0);

    attributes.clear();
    attributes.put(a1, "foo");
    attributes.put(a2, 7);
    first1 = store.createResource("first1", rootRes, firstClass, attributes);

    attributes.clear();
    attributes.put(a1, "abab");
    attributes.put(a2, 9);
    first2 = store.createResource("first2", rootRes, firstClass, attributes);

    ResourceClass<?> secondClass =
        schema.createResourceClass(
            "second",
            secondImpl.getResClass().getName(),
            secondImpl.getHandlerClass().getName(),
            secondImpl == Implementation.TABULAR ? "second" : null,
            0);
    a1 = schema.createAttribute("a1", stringAttr, null, null, 0);
    schema.addAttribute(secondClass, a1, null);
    a2 = schema.createAttribute("a2", intAttr, null, null, 0);
    schema.addAttribute(secondClass, a2, 0);
    a3 = schema.createAttribute("a3", resourceAttr, null, "first", 0);
    schema.addAttribute(secondClass, a3, null);
    AttributeDefinition<String> a4 = schema.createAttribute("a4", stringAttr, null, null, 0);
    schema.addAttribute(secondClass, a4, null);

    attributes.clear();
    attributes.put(a1, "foo");
    attributes.put(a2, 7);
    attributes.put(a3, first1);
    attributes.put(a4, "f%");
    second1 = store.createResource("second1", rootRes, secondClass, attributes);

    attributes.clear();
    attributes.put(a1, "bam");
    attributes.put(a2, 7);
    second2 = store.createResource("second2", rootRes, secondClass, attributes);

    ResourceClass<?> thirdClass =
        schema.createResourceClass(
            "third",
            thirdImpl.getResClass().getName(),
            thirdImpl.getHandlerClass().getName(),
            thirdImpl == Implementation.TABULAR ? "third" : null,
            0);
    a3 = schema.createAttribute("a3", resourceAttr, null, "first", 0);
    schema.addAttribute(thirdClass, a3, null);
    attributes.clear();
    schema.addParentClass(thirdClass, firstClass, attributes);
    a1 = firstClass.getAttribute("a1", String.class);
    a2 = firstClass.getAttribute("a2", Integer.class);

    attributes.put(a1, "quux");
    attributes.put(a2, 11);
    attributes.put(a3, first1);
    third1 = store.createResource("third1", rootRes, thirdClass, attributes);

    validateFixture(firstImpl, secondImpl, thirdImpl);
  }