Example usage for javax.xml.registry RegistryException RegistryException

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

Introduction

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

Prototype

public RegistryException(Throwable cause) 

Source Link

Document

Constructs a JAXRException object initialized with the given Throwable object.

Usage

From source file:it.cnr.icar.eric.server.common.Utility.java

/**
 *         Return ArrayList of ExternalLink that points to unresolvable Http URLs. Any
 *         non-Http URLs will not be checked. Any non-Http URLs and other types
 *         of URIs will not be checked. If the http response code is smaller than 200
 *         or bigger than 299, the http URL is considered invalid.
 *///from  www . j  a  va  2  s .  c  o m
public ArrayList<Object> validateURIs(ArrayList<?> sourceRegistryObjects) throws RegistryException {
    ArrayList<Object> invalidURLROs = new ArrayList<Object>();
    Iterator<?> iter = sourceRegistryObjects.iterator();

    while (iter.hasNext()) {
        Object ro = iter.next();
        String uRI = null;

        if (ro instanceof ExternalLinkType) {
            uRI = ((ExternalLinkType) ro).getExternalURI();
        } else if (ro instanceof ServiceBindingType) {
            uRI = ((ServiceBindingType) ro).getAccessURI();
        } else {
            throw new RegistryException(
                    ServerResourceBundle.getInstance().getString("message.unknownRegistryObjectType"));
        }

        if (!it.cnr.icar.eric.common.Utility.getInstance().isValidURI(uRI)) {
            invalidURLROs.add(ro);
        }
    }

    return invalidURLROs;
}

From source file:it.cnr.icar.eric.server.query.QueryManagerImpl.java

@SuppressWarnings("unchecked")
private AdhocQueryResponse processForSpecialQueryResults(ServerRequestContext context)
        throws RegistryException {
    AdhocQueryResponse ebAdhocQueryResponse = null;
    try {/* w ww  .  ja  v a2s  .  co  m*/

        // Must have been Optimization for a special query like
        // "urn:oasis:names:tc:ebxml-regrep:query:FindObjectByIdAndType"
        RegistryObjectListType ebRegistryObjectListType = BindingUtility.getInstance().rimFac
                .createRegistryObjectListType();
        ebRegistryObjectListType.getIdentifiable().addAll((context).getSpecialQueryResults());
        (context).setSpecialQueryResults(null);

        ebAdhocQueryResponse = BindingUtility.getInstance().queryFac.createAdhocQueryResponse();
        ebAdhocQueryResponse.setRegistryObjectList(ebRegistryObjectListType);
        ebAdhocQueryResponse.setStatus(BindingUtility.CANONICAL_RESPONSE_STATUS_TYPE_ID_Success);
        ebAdhocQueryResponse.setStartIndex(BigInteger.valueOf(0));
        ebAdhocQueryResponse.setTotalResultCount(BigInteger.valueOf((context).getQueryResults().size()));
    } catch (Throwable t) {
        throw new RegistryException(t);
    }
    return ebAdhocQueryResponse;
}

From source file:it.cnr.icar.eric.server.security.authorization.RegistryPolicyFinderModule.java

/**
 * Gets the id for the PolicySet object for the objects matching specified resourceId.
 *
 *///from  w  w w  . j a v  a2 s. c om
@SuppressWarnings("rawtypes")
private String getRegistryObjectPolicyId(ServerRequestContext context, String resourceId)
        throws RegistryException {
    String id = null;

    boolean assumeCanonicalObjectsUseDefaultACP = Boolean
            .valueOf(RegistryProperties.getInstance()
                    .getProperty("eric.security.authorization.assumeCanonicalObjectsUseDefaultACP", "true"))
            .booleanValue();
    boolean checkForCustomACP = Boolean
            .valueOf(RegistryProperties.getInstance()
                    .getProperty("eric.security.authorization.customAccessControlPoliciesEnabled", "false"))
            .booleanValue();

    if (!checkForCustomACP || (assumeCanonicalObjectsUseDefaultACP
            && it.cnr.icar.eric.common.Utility.isCanonicalObjectId(resourceId))) {
        getDefaultPolicy(context);
        return idForDefaultACP;
    } else {
        try {
            ResponseOptionType ebResponseOptionType = BindingUtility.getInstance().queryFac
                    .createResponseOptionType();
            ebResponseOptionType.setReturnType(ReturnType.LEAF_CLASS);
            ebResponseOptionType.setReturnComposedObjects(false);

            String query = "SELECT policy.* from ExtrinsicObject policy, Association ass WHERE ass.targetObject = '"
                    + resourceId + "' AND ass.associationType = '"
                    + BindingUtility.CANONICAL_ASSOCIATION_TYPE_ID_AccessControlPolicyFor
                    + "' AND ass.sourceObject = policy.id";

            List objectRefs = new ArrayList();
            List<IdentifiableType> ebIdentifiableTypeResultList = pm.executeSQLQuery(context, query,
                    ebResponseOptionType, "ExtrinsicObject", objectRefs);
            List<String> ids = bu.getIdsFromRegistryObjectTypes(ebIdentifiableTypeResultList);

            int cnt = ids.size();

            if (cnt == 0) {
                //No policy defined for the RegistryObject
                //See if a policy is defined for the ObjectType corresponding to this RegistryObject's objectType
                query = "SELECT policy.* from ExtrinsicObject policy, RegistryObject ro, ClassificationNode ot, Association ass WHERE ass.targetObject = ot.id AND ass.associationType = '"
                        + BindingUtility.CANONICAL_ASSOCIATION_TYPE_ID_AccessControlPolicyFor
                        + "' AND ass.sourceObject = policy.id AND ro.id = '" + resourceId
                        + "' AND ro.objectType = ot.id";

                objectRefs = new ArrayList();
                ebIdentifiableTypeResultList = pm.executeSQLQuery(context, query, ebResponseOptionType,
                        "ExtrinsicObject", objectRefs);
                ids = bu.getIdsFromRegistryObjectTypes(ebIdentifiableTypeResultList);

                cnt = ids.size();
            }

            if (cnt > 1) {
                log.warn(ServerResourceBundle.getInstance()
                        .getString("message.MoreThan1AccessControlPolicyWithId", new Object[] { resourceId }));
            }

            if (cnt >= 1) {
                id = ids.get(0);
            }

        } catch (RegistryException e) {
            context.rollback();
            throw e;
        } catch (Exception e) {
            context.rollback();
            throw new RegistryException(e);
        }

        context.commit();
    }

    log.trace("RegistryAttributeFinderModule.getRegistryObjectPolicyId: resourceId=" + resourceId + " policyId="
            + id);
    return id;
}

From source file:it.cnr.icar.eric.server.lcm.versioning.VersionProcessor.java

private List<IdentifiableType> getAllRegistryObjectVersions(RegistryObjectType ebRegistryObjectType)
        throws RegistryException {
    if (versions == null) {
        ServerRequestContext queryContext = null;

        // Note: ORDER BY versionName DESC is not safe because String(1.10)
        // < String(1.9)
        String query = "SELECT ro.* FROM " + Utility.getInstance().mapTableName(ebRegistryObjectType)
                + " ro WHERE ro.lid = '" + ebRegistryObjectType.getLid() + "'";

        try {// ww  w .ja  v  a 2  s .co m
            AdhocQueryRequest queryRequest = bu.createAdhocQueryRequest(query);
            queryContext = new ServerRequestContext("VersionProcessor.getAllRegistryObjectVersions",
                    queryRequest);

            queryContext.setUser(ac.registryOperator);

            AdhocQueryResponse ebAdhocQueryResponse = qm.submitAdhocQuery(queryContext);

            @SuppressWarnings("unchecked")
            List<IdentifiableType> ebIdentifiableTypeList = (List<IdentifiableType>) BindingUtility
                    .getInstance().getIdentifiableTypeList(ebAdhocQueryResponse.getRegistryObjectList());

            // set resulting list as versions
            versions = ebIdentifiableTypeList;

            queryContext.commit();
            queryContext = null;
        } catch (JAXBException e) {
            throw (new RegistryException(e));
        } catch (JAXRException e) {
            throw (new RegistryException(e));
        } finally {
            if (queryContext != null) {
                queryContext.rollback();
            }
        }
    }

    return (versions);
}

From source file:it.cnr.icar.eric.server.lcm.LifeCycleManagerImpl.java

/**
 * Processes Associations looking for Associations that already exist and
 * are being submitted by source or target owner and are identical in state
 * to existing Association in registry.//  w  w  w  .j  ava  2s  .com
 * 
 * ebXML Registry 3.0 hasber discarded association confirmation in favour of
 * Role Based access control. However, freebXML Registry supports it in an
 * impl specific manner as this is required by JAXR 1.0 API. This SHOULD be
 * removed once JAXR 2.0 no longer requires it for ebXML Registry in future.
 * 
 * The processing updates the Association to add a special Impl specific
 * slot to remember the confirmation state change.
 * 
 * TODO: Need to do unconfirm when src or target owner removes an
 * Association they had previously confirmed.
 */
private void processConfirmationAssociations(ServerRequestContext context) throws RegistryException {

    try {
        // Make a copy to avoid ConcurrentModificationException
        ArrayList<?> topLevelObjects = new ArrayList<Object>(
                (context).getTopLevelRegistryObjectTypeMap().values());
        Iterator<?> iter = topLevelObjects.iterator();
        while (iter.hasNext()) {
            Object obj = iter.next();
            if (obj instanceof AssociationType1) {
                AssociationType1 ass = (AssociationType1) obj;
                HashMap<String, Serializable> slotsMap = bu.getSlotsFromRegistryObject(ass);
                @SuppressWarnings("static-access")
                String beingConfirmed = (String) slotsMap.remove(bu.IMPL_SLOT_ASSOCIATION_IS_BEING_CONFIRMED);
                if ((beingConfirmed != null) && (beingConfirmed.equalsIgnoreCase("true"))) {
                    // Need to set slotMap again
                    ass.getSlot().clear();
                    bu.addSlotsToRegistryObject(ass, slotsMap);

                    (context).getConfirmationAssociations().put(ass.getId(), ass);
                }
            }
        }
    } catch (javax.xml.bind.JAXBException e) {
        throw new RegistryException(e);
    }
}

From source file:it.cnr.icar.eric.server.repository.hibernate.HibernateRepositoryManager.java

/**
 * Delete multiple repository items.//from  w ww .ja v  a 2 s  . c om
 * @param ids List of ids of ExtrinsicObjects whose repositoryItems are desired to be deleted.
 * @throws RegistryException if any of the item do not exist
 */
public void delete(@SuppressWarnings("rawtypes") List ids) throws RegistryException {
    Transaction tx = null;
    try {
        SessionContext sc = hu.getSessionContext();
        Session s = sc.getSession();
        tx = s.beginTransaction();

        @SuppressWarnings("unchecked")
        Set<RepositoryItemKey> keys = getKeysFromIds(ids);
        @SuppressWarnings("unused")
        Iterator<RepositoryItemKey> iter = keys.iterator();

        if (log.isDebugEnabled()) {
            StringBuffer message = new StringBuffer("Deleting repository items: ");
            for (Iterator<RepositoryItemKey> it = keys.iterator(); it.hasNext();) {
                message.append((it.next()).toString());
                if (it.hasNext()) {
                    message.append(", \n");
                } else {
                    message.append(".\n");
                }
            }
            log.debug(message);
        }

        String findByID = "from RepositoryItemBean as rib where rib.key.lid = ? AND rib.key.versionName = ? ";

        for (Iterator<RepositoryItemKey> it = keys.iterator(); it.hasNext();) {
            RepositoryItemKey key = it.next();

            String lid = key.getLid();
            String versionName = key.getVersionName();

            Object[] params = { lid, versionName };

            Type[] types = { Hibernate.STRING, Hibernate.STRING };

            int deleted = s.delete(findByID, params, types);

            if (deleted == 0) {
                throw new RegistryException(ServerResourceBundle.getInstance()
                        .getString("message.RepositoryItemDoesNotExist", new Object[] { lid, versionName }));
            }
        }

        tx.commit();

    } catch (RegistryException e) {
        tryRollback(tx);
        throw e;
    } catch (Exception e) {
        String msg = ServerResourceBundle.getInstance().getString("message.FailedToDeleteRepositoryItems");
        log.error(e, e);
        tryRollback(tx);
        throw new RegistryException(ServerResourceBundle.getInstance().getString("message.seeLogsForDetails",
                new Object[] { msg }));
    } finally {
        tryClose();
    }
}

From source file:it.cnr.icar.eric.server.security.authentication.AuthenticationServiceImpl.java

/**
 * Make sure user gets auto-classified as RegistryAdministrator if not so
 * already./*  w  w  w .j av a 2  s  . co m*/
 */
private void makeRegistryAdministrator(ServerRequestContext context, UserType user) throws RegistryException {

    try {
        if (user != null) {
            boolean isAdmin = hasRegistryAdministratorRole(user);

            if (!isAdmin) {
                /*
                 * ??? Need new message for this logging. // Log real
                 * changes to security realm -- new admins. if
                 * (log.isInfoEnabled()) {
                 * log.info(ServerResourceBundle.getInstance().
                 * getString("message.getRegistryAdministratorsAddingAdmin",
                 * new Object[]{user.getId()})); }
                 */
                ClassificationType ebClassificationType = BindingUtility.getInstance().rimFac
                        .createClassificationType();
                ebClassificationType.setId(it.cnr.icar.eric.common.Utility.getInstance().createId());
                ebClassificationType
                        .setClassificationNode(BindingUtility.CANONICAL_SUBJECT_ROLE_ID_RegistryAdministrator);
                ebClassificationType.setClassifiedObject(user.getId());
                user.getClassification().add(ebClassificationType);

                // Now persists updated User
                java.util.List<IdentifiableType> al = new java.util.ArrayList<IdentifiableType>();
                al.add(user);
                pm.update(context, al);
            }
        }

        // ??? This method did not create this context, should it commit?
        context.commit();
        // A local signal to the finally block below.
        context = null;
    } catch (RegistryException e) {
        throw e;
    } catch (Exception e) {
        throw new RegistryException(e);
    } finally {
        if (null != context) {
            // Oh no, it's still here...
            context.rollback();
        }
    }
}

From source file:it.cnr.icar.eric.server.query.QueryManagerImpl.java

private void processForQueryFilterPlugins(ServerRequestContext context) throws RegistryException {
    try {//from ww  w .  j  a  v a2  s  .c  o  m
        Map<?, ?> paramsMap = context.getQueryParamsMap();
        if (paramsMap != null) {
            Object obj = context.getQueryParamsMap().get("$queryFilterIds");
            if (obj != null) {
                if (obj instanceof String) {
                    String filterId = (String) obj;
                    QueryPlugin plugin = (QueryPlugin) queryPluginsMap.get(filterId);
                    plugin.processRequest(context);
                } else if (obj instanceof Collection) {
                    Collection<?> filterIds = (Collection<?>) obj;
                    Iterator<?> filterItr = filterIds.iterator();
                    while (filterItr.hasNext()) {
                        QueryPlugin plugin = (QueryPlugin) filterItr.next();
                        plugin.processRequest(context);
                    }
                } else {
                    String msg = ServerResourceBundle.getInstance().getString("invalidFilterQueryParamter",
                            new Object[] { obj.getClass().getName() });
                    throw new RegistryException(msg);
                }
            }
        }
    } catch (RegistryException re) {
        throw re;
    } catch (Throwable t) {
        throw new RegistryException(t);
    }
}

From source file:it.cnr.icar.eric.server.security.authentication.AuthenticationServiceImpl.java

private void loadPredefinedUsers() throws RegistryException {
    ServerRequestContext context = null;
    try {//from  w w w .j  av  a  2s. c o m
        context = new ServerRequestContext("AuthenticationServiceImpl.loadPredefinedUsers", null);
        registryOperator = (UserType) pm.getRegistryObject(context, ALIAS_REGISTRY_OPERATOR, "User");
        registryGuest = (UserType) pm.getRegistryObject(context, ALIAS_REGISTRY_GUEST, "User");
        farrukh = (UserType) pm.getRegistryObject(context, ALIAS_FARRUKH, "User");
        nikola = (UserType) pm.getRegistryObject(context, ALIAS_NIKOLA, "User");
        if (registryOperator == null) {
            throw new RegistryException(ServerResourceBundle.getInstance().getString("message.registryOperator",
                    new Object[] { ALIAS_REGISTRY_OPERATOR }));
        }
        if (registryGuest == null) {
            throw new RegistryException(ServerResourceBundle.getInstance().getString("message.registryGuest",
                    new Object[] { ALIAS_REGISTRY_GUEST }));
        }
    } catch (RegistryException e) {
        log.error(ServerResourceBundle.getInstance()
                .getString("message.InternalErrorCouldNotLoadPredefinedUsers"), e);
        throw e;
    }
}

From source file:it.cnr.icar.eric.server.persistence.rdb.AbstractDAO.java

/**
 * Saves content of a db column to an ExtrinsicObject / RepositoryItem pair.
 *
 * TODO: /*  w  w w. jav a2s.  c  o  m*/
 *
 * Need to enforce referential integrity by deleting spillover EO/RI when parent is deleted.
 * This should be done as part of the fix to prevent deletions when there are existing references
 * by treating spillover objects as if they are referenced by their parent.      
 *
 * @param parentId the id of the parent object whose column data is being "spilled over"
 * @param columnInfo contains information on the table and column whose data is being spilledOver. Format SHOULD be tableName:columnName)
 * @param columnData contains the column data being "spilled over" into RepositoryItem
 *
 * @return the id of the "spill over" repository item
 */
protected String marshalToRepositoryItem(String parentId, String columnInfo, String columnData)
        throws RegistryException {

    String spillOverId = getSpillOverRepositoryItemId(parentId, columnInfo);

    try {
        ExtrinsicObjectType ebExtrinsicObjectType = bu.rimFac.createExtrinsicObjectType();
        ebExtrinsicObjectType.setId(spillOverId);
        ebExtrinsicObjectType.setLid(spillOverId);
        ebExtrinsicObjectType.setMimeType("text/plain");

        VersionInfoType versionInfo = bu.rimFac.createVersionInfoType();
        versionInfo.setVersionName("1.1");
        ebExtrinsicObjectType.setVersionInfo(versionInfo);
        ebExtrinsicObjectType.setContentVersionInfo(versionInfo);

        ExtrinsicObjectDAO extrinsicObjectDAO = new ExtrinsicObjectDAO(context);

        //Delete any previous eo and ri
        removeSpillOverRepositoryItem(parentId, columnInfo);

        RepositoryItem ebRepositoryItem = it.cnr.icar.eric.common.Utility.getInstance()
                .createRepositoryItem(spillOverId, columnData);

        //Insert the extrinsic objects

        //Need to place ri in RepositoryItemsMap otherwise ExtrinsicObjectDAO will not set contentVersionInfo.versionName
        context.getRepositoryItemsMap().put(spillOverId, ebRepositoryItem);
        ArrayList<ExtrinsicObjectType> extrinsicObjects = new ArrayList<ExtrinsicObjectType>();
        extrinsicObjects.add(ebExtrinsicObjectType);
        extrinsicObjectDAO.insert(extrinsicObjects);

        //Inserting the repository item
        rm.insert((context), ebRepositoryItem);

        //Remove ri from RepositoryItemsMap to otherwise it will create problems in lcm.submitObjects wrapUp
        context.getRepositoryItemsMap().remove(spillOverId);
    } catch (RegistryException e) {
        throw e;
    } catch (Exception e) {
        throw new RegistryException(e);
    }

    return spillOverId;
}