Example usage for javax.xml.registry JAXRException JAXRException

List of usage examples for javax.xml.registry JAXRException JAXRException

Introduction

In this page you can find the example usage for javax.xml.registry JAXRException JAXRException.

Prototype

public JAXRException() 

Source Link

Document

Constructs a JAXRException object with no reason or embedded Throwable.

Usage

From source file:de.kp.ames.web.function.bulletin.PostingLCM.java

/**
 * Submit comment for a certain posting/*w w  w .  j  a  va  2  s  .c  o  m*/
 * 
 * @param posting
 * @param data
 * @return
 * @throws Exception
 */
public String submitComment(String posting, String data) throws Exception {

    /*
     * Create or retrieve registry package that is 
     * responsible for managing comments
     */
    RegistryPackageImpl container = null;
    JaxrDQM dqm = new JaxrDQM(jaxrHandle);

    List<RegistryPackageImpl> list = dqm.getRegistryPackage_ByClasNode(ClassificationConstants.FNC_ID_Comment);
    if (list.size() == 0) {
        /*
         * Create container
         */
        container = createCommentPackage();

    } else {
        /*
         * Retrieve container
         */
        container = list.get(0);

    }

    /* 
     * A comment is a certain extrinsic object that holds all relevant
     * and related information in a single JSON repository item
     */

    ExtrinsicObjectImpl eo = null;
    JaxrTransaction transaction = new JaxrTransaction();

    // create extrinsic object that serves as a container for
    // the respective comment
    eo = createExtrinsicObject();
    if (eo == null)
        throw new JAXRException();

    /* 
     * Identifier
     */
    String eid = JaxrIdentity.getInstance().getPrefixUID(FncConstants.COMMENT_PRE);

    /*
    * Name & description using default locale
    */

    JSONObject jPosting = new JSONObject(data);

    String name = "[COMMENT] " + jPosting.getString(JaxrConstants.RIM_NAME);
    String desc = "[SUBJ] " + jPosting.getString(JaxrConstants.RIM_SUBJECT);

    /* 
     * Home url
     */
    String home = jaxrHandle.getEndpoint().replace("/saml", "");

    /*
     * Set properties
     */
    setProperties(eo, eid, name, desc, home);

    /* 
     * Mime type & handler
     */
    String mimetype = GlobalConstants.MT_JSON;
    eo.setMimeType(mimetype);

    byte[] bytes = data.getBytes(GlobalConstants.UTF_8);

    DataHandler handler = new DataHandler(FileUtil.createByteArrayDataSource(bytes, mimetype));
    eo.setRepositoryItem(handler);

    /*
     * Create classification
     */
    ClassificationImpl c = createClassification(ClassificationConstants.FNC_ID_Comment);
    c.setName(createInternationalString(Locale.US, "Comment Classification"));

    /* 
     * Associate classification and posting container
     */
    eo.addClassification(c);

    /* 
     * Add extrinsic object to container
     */
    container.addRegistryObject(eo);

    /*
     * Create association
     */
    String aid = JaxrIdentity.getInstance().getPrefixUID(FncConstants.COMMENT_PRE);
    AssociationImpl a = this.createAssociation_RelatedTo(eo);
    /*
     * Set properties
     */
    setProperties(a, aid, "Posting Link",
            "This is a directed association between a posting and the respective comment.", home);

    /*
     * Source object
     */
    ExtrinsicObjectImpl so = (ExtrinsicObjectImpl) jaxrHandle.getDQM().getRegistryObject(posting);

    so.addAssociation(a);

    /*
     * Add association to container
     */
    container.addRegistryObject(a);

    /*
     * Save objects
     */
    confirmAssociation(a);

    transaction.addObjectToSave(container);
    saveObjects(transaction.getObjectsToSave(), false, false);

    /*
     * Supply reactor
     */
    ReactorParams reactorParams = new ReactorParams(jaxrHandle, eo, ClassificationConstants.FNC_ID_Comment,
            RAction.C_INDEX);
    ReactorImpl.onSubmit(reactorParams);

    /*
     * Retrieve response message
     */
    JSONObject jResponse = transaction.getJResponse(eid, FncMessages.COMMENT_CREATED);
    return jResponse.toString();

}

From source file:de.kp.ames.web.function.bulletin.PostingLCM.java

/**
 * Submit posting for a certain recipient; a posting is an 
 * extrinsic object that is classified as posting and contained
 * within the respective positing container; 
 * //  ww w.j a  va 2s  .  co m
 * the association to the addressed recipient is mapped onto an 
 * association instance
 * 
 * @param recipient
 * @param data
 * @return
 * @throws Exception 
 */
public String submitPosting(String recipient, String data) throws Exception {

    /*
     * Create or retrieve registry package that is 
     * responsible for managing posting
     */
    RegistryPackageImpl container = null;
    JaxrDQM dqm = new JaxrDQM(jaxrHandle);

    List<RegistryPackageImpl> list = dqm.getRegistryPackage_ByClasNode(ClassificationConstants.FNC_ID_Posting);
    if (list.size() == 0) {
        /*
         * Create container
         */
        container = createPostingPackage();

    } else {
        /*
         * Retrieve container
         */
        container = list.get(0);

    }

    /* 
     * A posting is a certain extrinsic object that holds all relevant
     * and related information in a single JSON repository item
     */
    ExtrinsicObjectImpl eo = null;
    JaxrTransaction transaction = new JaxrTransaction();

    /* 
     * Create extrinsic object that serves as a container for
     * the respective posting
     */
    eo = createExtrinsicObject();
    if (eo == null)
        throw new JAXRException();

    /* 
     * Identifier
     */
    String eid = JaxrIdentity.getInstance().getPrefixUID(FncConstants.POSTING_PRE);

    /*
    * Name & description using default locale
    */
    JSONObject jPosting = new JSONObject(data);

    /*
     * Name is the 'name' of the recipient
     */
    String name = "[POST] " + jPosting.getString(JaxrConstants.RIM_NAME);
    String desc = "[SUBJ] " + jPosting.getString(JaxrConstants.RIM_SUBJECT);

    /* 
     * Home url
     */
    String home = jaxrHandle.getEndpoint().replace("/saml", "");

    /*
     * Set properties
     */
    setProperties(eo, eid, name, desc, home);

    /* 
     * Mime type & handler
     */
    String mimetype = GlobalConstants.MT_JSON;
    eo.setMimeType(mimetype);

    byte[] bytes = data.getBytes(GlobalConstants.UTF_8);

    DataHandler handler = new DataHandler(FileUtil.createByteArrayDataSource(bytes, mimetype));
    eo.setRepositoryItem(handler);

    /*
     * Create classification
     */
    ClassificationImpl c = createClassification(ClassificationConstants.FNC_ID_Posting);
    c.setName(createInternationalString(Locale.US, "Posting Classification"));

    /* 
     * Associate classification and posting container
     */
    eo.addClassification(c);

    /* 
     * Add extrinsic object to container
     */
    container.addRegistryObject(eo);

    /*
     * Create association
     */
    String aid = JaxrIdentity.getInstance().getPrefixUID(FncConstants.POSTING_PRE);
    AssociationImpl a = this.createAssociation_RelatedTo(eo);
    /*
     * Set properties
     */
    setProperties(a, aid, "Recipient Link",
            "This is a directed association between a recipient and the respective posting.", home);

    /*
     * Source object (could be User or Organization)
     */

    RegistryObject so = (RegistryObject) jaxrHandle.getDQM().getRegistryObject(recipient);

    so.addAssociation(a);

    /*
     * Add association to container
     */
    container.addRegistryObject(a);

    /*
     * Save objects
     */
    confirmAssociation(a);

    /*
     * Only the registryPackage needs to be added for save
     * All dependent objects will be added automatically 
     */
    transaction.addObjectToSave(container);
    saveObjects(transaction.getObjectsToSave(), false, false);

    /*
     * Supply reactor
     */
    ReactorParams reactorParams = new ReactorParams(jaxrHandle, eo, ClassificationConstants.FNC_ID_Posting,
            RAction.C_INDEX);
    ReactorImpl.onSubmit(reactorParams);

    /*
     * Retrieve response message
     */
    JSONObject jResponse = transaction.getJResponse(eid, FncMessages.POSTING_CREATED);
    return jResponse.toString();

}