[Registry-dev] svn commit r15791 - in
trunk/registry/modules/core/src/main/java/org/wso2/registry:
. app jdbc jdbc/dao secure
svn at wso2.org
svn at wso2.org
Fri Apr 18 02:08:44 PDT 2008
Author: deepal
Date: Fri Apr 18 02:08:27 2008
New Revision: 15791
Log:
added a way to remove associations
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/Registry.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/APPConstants.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/AtomRegistry.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/VersionedResourceDAO.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/secure/SecureRegistry.java
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/Registry.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/Registry.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/Registry.java Fri Apr 18 02:08:27 2008
@@ -95,6 +95,18 @@
String sourcePath,
String associationPaths) throws RegistryException;
+
+ /**
+ * To remove an association for a given resource
+ *
+ * @param associationType Type of the association
+ * @param sourcePath Path of the dependent resource
+ * @param associationPaths Paths of dependency resources
+ * @throws RegistryException Depends on the implementation
+ */
+ void removeAssociation(String associationType,
+ String sourcePath,
+ String associationPaths) throws RegistryException;
/**
* Get all associations of the given resource. This is a chain of association starting from the
* given resource both upwards (source to destination) and downwards (destination to source). T
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/app/APPConstants.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/app/APPConstants.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/app/APPConstants.java Fri Apr 18 02:08:27 2008
@@ -50,6 +50,7 @@
static final String PARAMETER_GET_ASPECT_ACTIONS = "getAspectActions";
static final String PARAMETER_ADD_ASSOCIATION = "associate";
+ static final String PARAMETER_REMOVE_ASSOCIATION = "removeassociate";
static final String PARAMETER_GET_ALL_ASSOCIATION = "getAllassociations";
static final String PARAMETER_GET_ALL_ASSOCIATION_FOR_TYPE = "getAssociations";
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/app/AtomRegistry.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/app/AtomRegistry.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/app/AtomRegistry.java Fri Apr 18 02:08:27 2008
@@ -315,6 +315,11 @@
String associationType = entry.getSummary();
getSecureRegistry(request)
.addAssociation(associationType, values[0] , destinationPath);
+ } else if (PARAMETER_REMOVE_ASSOCIATION.equals(operation)) {
+ String destinationPath = entry.getContent();
+ String associationType = entry.getSummary();
+ getSecureRegistry(request)
+ .removeAssociation(associationType, values[0] , destinationPath);
}
}
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java Fri Apr 18 02:08:27 2008
@@ -507,7 +507,7 @@
ClientResponse resp = abderaClient.post(baseURI + APPConstants.ATOM +
encodeURL(sourcePath +
RegistryConstants.URL_SEPARATOR +
- ASSOCIATIONS),
+ PARAMETER_ADD_ASSOCIATION),
el,
getAuthorization());
if (resp.getType() == Response.ResponseType.SUCCESS) {
@@ -519,6 +519,26 @@
}
+ public void removeAssociation(String associationType, String sourcePath, String associationPaths) throws RegistryException {
+ AbderaClient abderaClient = new AbderaClient(abdera);
+ final Factory factory = abdera.getFactory();
+ Element el = factory.newElement(QNAME_ASSOC);
+ el.setAttributeValue(ASSOC_TYPE, associationType);
+ el.setText(associationPaths);
+ ClientResponse resp = abderaClient.put(baseURI + APPConstants.ATOM +
+ encodeURL(sourcePath +
+ RegistryConstants.URL_SEPARATOR +
+ PARAMETER_REMOVE_ASSOCIATION),
+ el,
+ getAuthorization());
+ if (resp.getType() == Response.ResponseType.SUCCESS) {
+ log.info(Messages.getMessage("resource.associated", sourcePath));
+ } else {
+ log.error(Messages.getMessage("resource.associated.fails", sourcePath));
+ throw new RegistryException(Messages.getMessage("resource.tag.fails", sourcePath));
+ }
+ }
+
public Association[] getAllAssociations(String resourcePath) throws RegistryException {
AbderaClient abderaClient = new AbderaClient(abdera);
ClientResponse clientResponse = abderaClient.get(baseURI + APPConstants.ATOM +
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java Fri Apr 18 02:08:27 2008
@@ -644,6 +644,34 @@
}
}
+
+ public void removeAssociation(String associationType, String sourcePath, String associationPath) throws RegistryException {
+ Connection conn = null;
+ try {
+ conn = getConnection();
+ long sourceResourceID = resourceDAO.getResourceID(sourcePath, conn);
+ long destinationResourceID = resourceDAO.getResourceID(associationPath, conn);
+ resourceDAO.removeAssociation(sourceResourceID , destinationResourceID , associationType ,conn);
+ } catch (SQLException e) {
+ String msg = "Failed to add dependencies for the resource: " + sourcePath;
+ log.error(msg, e);
+ try {
+ conn.rollback();
+ } catch (SQLException e1) {
+ log.error(e1);
+ }
+ throw new RegistryException(msg, e);
+ } finally {
+ if (conn != null) {
+ try {
+ conn.close();
+ } catch (SQLException ignore) {
+ log.info(Messages.getMessage("exception.closing.db"));
+ }
+ }
+ }
+ }
+
public Association[] getAllAssociations(String resourcePath) throws RegistryException {
Connection conn = null;
try {
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/VersionedResourceDAO.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/VersionedResourceDAO.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/VersionedResourceDAO.java Fri Apr 18 02:08:27 2008
@@ -134,6 +134,20 @@
statement.executeUpdate();
}
+ public void removeAssociation(long sourceID ,
+ long associationID ,
+ String associationType ,
+ Connection con) throws SQLException {
+ String propSQL = "DELETE FROM ASSOCIATION WHERE RID1=? AND RID2=? AND ASSOCIATION_TYPE=?";
+ PreparedStatement statement = con.prepareStatement(propSQL);
+ statement.setLong(1, sourceID);
+ statement.setLong(2,associationID);
+ statement.setString(3,associationType);
+ statement.executeUpdate();
+ }
+
+
+
public Association[] getAllAssociations(String resourcePath, Connection con) throws SQLException{
long resourceID = getResourceID(resourcePath , con);
String propSQL = "SELECT RID2 , ASSOCIATION_TYPE FROM ASSOCIATION WHERE RID1=?";
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/secure/SecureRegistry.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/secure/SecureRegistry.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/secure/SecureRegistry.java Fri Apr 18 02:08:27 2008
@@ -454,6 +454,26 @@
}
+ public void removeAssociation(String associationType, String sourcePath, String associationPaths) throws RegistryException {
+ String authPath = getAuthorizationPath(sourcePath);
+
+ try {
+ if (!authorizer.isUserAuthorized(userID, authPath, ActionConstants.PUT)) {
+ String msg =
+ "User: " + userID + " does not have write permission on the resource: " +
+ authPath + ". Users should have write permission to specify that " +
+ "resource is dependent on another resource.";
+ log.info(msg);
+ throw new AuthorizationFailedException(msg);
+ }
+ } catch (UserStoreException e) {
+ String msg = "Could not check authorization. \nCaused by " + e.getMessage();
+ log.error(msg, e);
+ throw new RegistryException(msg, e);
+ }
+ registry.removeAssociation(associationType, sourcePath, associationPaths);
+ }
+
public void applyTag(String resourcePath, String tag) throws RegistryException {
String authorizationPath = getAuthorizationPath(resourcePath);
More information about the Registry-dev
mailing list