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.persistence.rdb.PostalAddressDAO.java

/**
*         @param registryObjects is a List of Organizations or Users
*         @throws RegistryException if the RegistryObject is not Organization or User,
*         or it has SQLException when inserting their PostalAddress
*//*from www .j  a  v a2s. co  m*/
@SuppressWarnings("resource")
public void insert(@SuppressWarnings("rawtypes") List registryObjects) throws RegistryException {
    Statement stmt = null;

    if (registryObjects.size() == 0) {
        return;
    }

    try {
        /*
        String sqlStr = "INSERT INTO " + getTableName() +
                      " VALUES( " +
                                                   "?, " + // city
                                                   "?, " + // country
                                                   "?, " + // postalCode
                                                   "?, " + // state
                                                   "?, " + // street
                                                   "?, " + // streetNum
                                                   "?)"; // Parent id
                
        PreparedStatement pstmt = context.getConnection().prepareStatement(sqlStr);
        */
        stmt = context.getConnection().createStatement();

        Iterator<?> rosIter = registryObjects.iterator();

        while (rosIter.hasNext()) {
            Object ro = rosIter.next();
            String parentId = null;
            PostalAddressType postalAddress = null;

            if (ro instanceof OrganizationType) {
                OrganizationType org = (OrganizationType) ro;
                postalAddress = org.getAddress().get(0);
                parentId = org.getId();
            } else if (ro instanceof UserType) {
                UserType user = (UserType) ro;

                //TODO: Save extra addresses, if required
                postalAddress = user.getAddress().get(0);
                parentId = user.getId();
            } else {
                throw new RegistryException(
                        ServerResourceBundle.getInstance().getString("message.incorrectRegistryObject"));
            }

            /*
            stmt.setString(1, postalAddress.getCity());
                        stmt.setString(2, postalAddress.getCountry());
            stmt.setString(3, postalAddress.getPostalCode());
            stmt.setString(4, postalAddress.getStateOrProvince());
            stmt.setString(5, postalAddress.getStreet());
            stmt.setString(6, postalAddress.getStreetNumber());
            stmt.setString(7, org.getId());
            stmt.addBatch();*/
            String city = postalAddress.getCity();

            if (city != null) {
                city = "'" + city + "'";
            }

            String country = postalAddress.getCountry();

            if (country != null) {
                country = "'" + country + "'";
            }

            String postalCode = postalAddress.getPostalCode();

            if (postalCode != null) {
                postalCode = "'" + postalCode + "'";
            }

            String state = postalAddress.getStateOrProvince();

            if (state != null) {
                state = "'" + state + "'";
            }

            String street = postalAddress.getStreet();

            if (street != null) {
                street = "'" + street + "'";
            }

            String streetNum = postalAddress.getStreetNumber();

            if (streetNum != null) {
                streetNum = "'" + streetNum + "'";
            }

            String str = "INSERT INTO PostalAddress " + "VALUES( " + city + ", " + country + ", " + postalCode
                    + ", " + state + ", " + street + ", " + streetNum + ", " + "'" + parentId + "' )";
            log.trace("stmt = " + str);
            stmt.addBatch(str);
        }

        // end looping all Organizations 
        if (registryObjects.size() > 0) {
            stmt.executeBatch();
        }
    } catch (SQLException e) {
        RegistryException exception = new RegistryException(e);
        throw exception;
    } finally {
        closeStatement(stmt);
    }
}

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

public void insert(@SuppressWarnings("rawtypes") List users) throws RegistryException {
    // log.info(ServerResourceBundle.getInstance().getString("message.InsertingEmailAddresss", new Object[]{new Integer(emailAddresss.size())}));
    if (users.size() == 0) {
        return;/*from w w  w  .jav  a2s .c  o  m*/
    }

    Statement stmt = null;

    try {
        Iterator<?> usersIter = users.iterator();
        stmt = context.getConnection().createStatement();

        while (usersIter.hasNext()) {
            UserType user = (UserType) usersIter.next();

            if (log.isDebugEnabled()) {
                try {
                    StringWriter writer = new StringWriter();
                    //                        bu.rimFac.createMarshaller()
                    bu.getJAXBContext().createMarshaller().marshal(user, writer);
                    log.debug("Inserting user: " + writer.getBuffer().toString());
                } catch (Exception e) {
                    log.debug("Failed to marshal user: ", e);
                }
            }

            String parentId = user.getId();

            List<EmailAddressType> emails = user.getEmailAddress();
            Iterator<EmailAddressType> emailsIter = emails.iterator();

            while (emailsIter.hasNext()) {
                //Log.print(Log.TRACE, 8, "\tDATABASE EVENT: storing EmailAddress " );
                Object obj = emailsIter.next();

                EmailAddressType emailAddress = (EmailAddressType) obj;

                String address = emailAddress.getAddress();

                String type = emailAddress.getType();

                if (type != null) {
                    type = "'" + type + "'";
                }

                String str = "INSERT INTO " + getTableName() + " VALUES( " + "'" + address + "', " + type + ", "
                        + "'" + parentId + "' )";
                log.trace("stmt = " + str);
                stmt.addBatch(str);
            }
        }

        if (users.size() > 0) {
            stmt.executeBatch();
        }
    } catch (SQLException e) {
        RegistryException exception = new RegistryException(e);
        throw exception;
    } finally {
        closeStatement(stmt);
    }
}

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

List<String> getUsageParametersByParent(String parentId) throws RegistryException {
    ArrayList<String> usageParams = new ArrayList<String>();
    PreparedStatement stmt = null;

    try {/*from  w w w .  j  a v a2  s.  c om*/
        String sql = "SELECT * FROM UsageParameter WHERE parent = ?";
        stmt = context.getConnection().prepareStatement(sql);
        stmt.setString(1, parentId);

        ResultSet rs = stmt.executeQuery();

        while (rs.next()) {
            String usageParam = new String();
            loadObject(usageParam, rs);
            usageParams.add(rs.getString("value"));
        }
    } catch (SQLException e) {
        log.error(ServerResourceBundle.getInstance().getString("message.CaughtException1"), e);
        throw new RegistryException(e);
    } finally {
        closeStatement(stmt);
    }

    return usageParams;
}

From source file:it.cnr.icar.eric.server.plugin.RequestInterceptorManager.java

private List<RequestInterceptor> getApplicablePlugins(ServerRequestContext context) throws RegistryException {
    List<RequestInterceptor> applicablePlugins = new ArrayList<RequestInterceptor>();

    try {/*from   w  w  w .  j a va  2  s  .  c  o  m*/
        if (getInterceptors().size() > 0) {
            @SuppressWarnings({ "static-access", "unused" })
            String requestAction = bu.getActionFromRequest(context.getCurrentRegistryRequest());

            //Get roles associated with user associated with this RequestContext
            Set<?> subjectRoles = ServerCache.getInstance().getRoles(context);

            //Now get those RequestInterceptors whose roles are a proper subset of subjectRoles
            Iterator<RequestInterceptor> iter = getInterceptors().iterator();
            while (iter.hasNext()) {
                RequestInterceptor interceptor = iter.next();
                Set<?> interceptorRoles = interceptor.getRoles();
                @SuppressWarnings("unused")
                Set<?> interceptorActions = interceptor.getActions();
                if ((subjectRoles.containsAll(interceptorRoles))) {
                    applicablePlugins.add(interceptor);
                }
            }
        }
    } catch (JAXRException e) {
        throw new RegistryException(e);
    }

    return applicablePlugins;
}

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

public EvaluationResult evaluate(@SuppressWarnings("rawtypes") List inputs, EvaluationCtx context) {
    // Evaluate the arguments using the helper method...this will
    // catch any errors, and return values that can be compared
    AttributeValue[] argValues = new AttributeValue[inputs.size()];
    EvaluationResult result = evalArgs(inputs, context, argValues, minParams);

    if (result != null) {
        return result;
    }/*  w  ww . ja  v  a  2 s  . c  o m*/

    // cast the resolved values into specific types
    String cnode1Id = (argValues[0]).encode().trim();
    String cnode2Id = (argValues[1]).encode().trim();

    boolean evalResult = false;

    //First see if we have an exact match on cnode id
    if (cnode1Id.equals(cnode2Id)) {
        evalResult = true;
    } else {
        // now see if the ClassificationNode identified by str1 ancestor
        //of ClassificationNode identified by str2
        try {
            ServerRequestContext requestContext = AuthorizationServiceImpl.getRequestContext(context);

            RegistryObjectType cnode1 = qm.getRegistryObject(requestContext, cnode1Id);
            if (!(cnode1 instanceof ClassificationNodeType)) {
                throw new RegistryException(ServerResourceBundle.getInstance()
                        .getString("message.ClassificationNodeExpected", new Object[] { cnode1.getClass() }));
            }

            RegistryObjectType cnode2 = qm.getRegistryObject(requestContext, cnode2Id);
            if (!(cnode2 instanceof ClassificationNodeType)) {
                throw new RegistryException(ServerResourceBundle.getInstance()
                        .getString("message.ClassificationNodeExpected", new Object[] { cnode2.getClass() }));
            }

            String path1 = ((ClassificationNodeType) cnode1).getPath();
            String path2 = ((ClassificationNodeType) cnode2).getPath();

            if (path2.startsWith(path1)) {
                evalResult = true;
            }
        } catch (RegistryException e) {
            log.error(ServerResourceBundle.getInstance().getString("message.xacmlExtFunctionEvalError",
                    new Object[] { getFunctionName() }), e);
            ArrayList<String> codes = new ArrayList<String>();
            codes.add(Status.STATUS_PROCESSING_ERROR);
            return new EvaluationResult(new Status(codes, e.getMessage()));
        }
    }

    // boolean returns are common, so there's a getInstance() for that
    return EvaluationResult.getInstance(evalResult);
}

From source file:it.cnr.icar.eric.server.cms.AbstractContentManagementService.java

protected AttachmentPart getRepositoryItemAsAttachmentPart(String id) throws RegistryException {
    RepositoryItem ri = rm.getRepositoryItem(id);

    AttachmentPart ap = null;/*from ww w. j a  va 2 s .  co  m*/

    try {
        SOAPMessage m = mf.createMessage();
        DataHandler dh = ri.getDataHandler();
        String cid = WSS4JSecurityUtilBST.convertUUIDToContentId(id);
        ap = m.createAttachmentPart(dh);
        ap.setContentId(cid);

    } catch (Exception e) {
        throw new RegistryException(e);
    }

    return ap;
}

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

List<SlotType1> getSlotsByParent(String parentId) throws RegistryException {
    List<SlotType1> slots = new ArrayList<SlotType1>();
    PreparedStatement stmt = null;

    try {/*www  .j  a v a  2s  . co  m*/
        String sql = "SELECT * FROM " + getTableName() + " WHERE parent = ? ORDER BY name_, sequenceId ASC";
        stmt = context.getConnection().prepareStatement(sql);
        stmt.setString(1, parentId);

        ResultSet rs = stmt.executeQuery();

        String lastName = "";
        SlotType1 ebSlotType = null;
        ValueListType ebValueListType = null;

        while (rs.next()) {
            //int sequenceId = rs.getInt("sequenceId");
            String name = rs.getString("name_");
            String slotType = rs.getString("slotType");
            String value = rs.getString("value");

            if (!name.equals(lastName)) {
                ebSlotType = bu.rimFac.createSlotType1();
                ebSlotType.setName(name);

                if (slotType != null) {
                    ebSlotType.setSlotType(slotType);
                }

                ebValueListType = bu.rimFac.createValueListType();
                ebSlotType.setValueList(ebValueListType);
                slots.add(ebSlotType);
            }

            lastName = name;

            if (value != null) {
                ebValueListType.getValue().add(value);
            }
        }
    } catch (SQLException e) {
        log.error(ServerResourceBundle.getInstance().getString("message.CaughtException1"), e);
        throw new RegistryException(e);
    } finally {
        closeStatement(stmt);
    }

    return slots;
}

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

private AbstractPolicy loadDefaultPolicy(ServerRequestContext requestContext) throws RegistryException {
    AbstractPolicy policy = null;//  ww w  .  j  a  v a 2s  . c o m
    try {
        idForDefaultACP = RegistryProperties.getInstance()
                .getProperty("eric.security.authorization.defaultACP");
        policy = loadPolicy(requestContext, idForDefaultACP);
        if (policy == null) {
            throw new RegistryException(
                    ServerResourceBundle.getInstance().getString("message.defaultAccessControlPolicy"));
        }
    } catch (RegistryException e) {
        throw new RegistryException(
                ServerResourceBundle.getInstance().getString("message.defaultAccessControlPolicy"), e);
    }
    return policy;
}

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

protected String checkClassificationReferences(java.sql.Connection conn, String schemeId)
        throws RegistryException {
    String classId = null;/*from  w w  w  .j a  v a  2  s.c o m*/
    PreparedStatement stmt = null;

    try {
        String sql = "SELECT id FROM Classification WHERE "
                + "classificationScheme=? AND classificationScheme IS NOT NULL";
        stmt = context.getConnection().prepareStatement(sql);
        stmt.setString(1, schemeId);
        ResultSet rs = stmt.executeQuery();

        if (rs.next()) {
            classId = rs.getString(1);
        }

        return classId;
    } catch (SQLException e) {
        throw new RegistryException(e);
    } finally {
        closeStatement(stmt);
    }
}

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

@SuppressWarnings({ "rawtypes", "unchecked" })
protected void loadObject(Object obj, ResultSet rs) throws RegistryException {
    try {//from  w  ww.  j a va 2s  .c  o  m
        if (!(obj instanceof OrganizationType)) {
            throw new RegistryException(ServerResourceBundle.getInstance()
                    .getString("message.OrganizationExpected", new Object[] { obj }));
        }

        OrganizationType ebOrganizationType = (OrganizationType) obj;
        super.loadObject(obj, rs);

        String parentId = rs.getString("parent");

        if (parentId != null) {
            ObjectRefType ebObjectRefType = bu.rimFac.createObjectRefType();
            ebObjectRefType.setId(parentId);
            context.getObjectRefs().add(ebObjectRefType);
            ebOrganizationType.setParent(parentId);
        }

        String primaryContactId = rs.getString("primaryContact");

        ObjectRefType ebObjectRefType = bu.rimFac.createObjectRefType();
        ebObjectRefType.setId(primaryContactId);
        context.getObjectRefs().add(ebObjectRefType);
        ebOrganizationType.setPrimaryContact(primaryContactId);

        PostalAddressDAO postalAddressDAO = new PostalAddressDAO(context);
        postalAddressDAO.setParent(ebOrganizationType);
        List addresses = postalAddressDAO.getByParent();
        if ((addresses != null) && (addresses.size() > 0)) {
            ebOrganizationType.getAddress().addAll(addresses);
        }

        TelephoneNumberDAO telephoneNumberDAO = new TelephoneNumberDAO(context);
        telephoneNumberDAO.setParent(ebOrganizationType);
        List phones = telephoneNumberDAO.getByParent();
        if (phones != null) {
            ebOrganizationType.getTelephoneNumber().addAll(phones);
        }

        EmailAddressDAO emailAddressDAO = new EmailAddressDAO(context);
        emailAddressDAO.setParent(ebOrganizationType);
        List emails = emailAddressDAO.getByParent();
        if (emails != null) {
            ebOrganizationType.getEmailAddress().addAll(emails);
        }
    } catch (SQLException e) {
        log.error(ServerResourceBundle.getInstance().getString("message.CaughtException1"), e);
        throw new RegistryException(e);
    }
}