Author: keith Date: Tue Jul 8 07:30:22 2008 New Revision: 18987 URL: http://wso2.org/svn/browse/wso2?view=rev&revision=18987
Log: More additions to address registry patch Added: trunk/mashup/java/modules/patches/registry/src/org/wso2/registry/LogEntry.java trunk/mashup/java/modules/patches/registry/src/org/wso2/registry/jdbc/dao/ trunk/mashup/java/modules/patches/registry/src/org/wso2/registry/jdbc/dao/AssociationDAO.java Added: trunk/mashup/java/modules/patches/registry/src/org/wso2/registry/LogEntry.java URL: http://wso2.org/svn/browse/wso2/trunk/mashup/java/modules/patches/registry/src/org/wso2/registry/LogEntry.java?pathrev=18987 ============================================================================== --- (empty file) +++ trunk/mashup/java/modules/patches/registry/src/org/wso2/registry/LogEntry.java Tue Jul 8 07:30:22 2008 @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2008, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.wso2.registry; + +import java.util.Date; + +/** + * Representation of a log entry. Log entry is a record of a single action performed on the + * registry. + */ +public class LogEntry { + + // Filters for log queries - these represent the possible actions that get logged. + public static final int ALL = -1; + public static final int ADD = 0; + public static final int UPDATE = 1; + public static final int COMMENT = 2; + public static final int TAG = 3; + public static final int RATING = 4; + public static final int DELETE_RESOURCE = 5; + public static final int RESTORE = 6; + public static final int RENAME = 7; + public static final int MOVE = 8; + public static final int COPY = 9; + + /** Path of the resource on which the action is performed. */ + private String resourcePath; + + /** User who has performed the action. */ + private String userName; + + /** Date and time at which the action is performed. */ + private Date date; + + /** Name of the actions. e.g. put, tag, comment */ + private int action; + + /** + * Additional data to describe the actions. This depends on the action. e.g. comment text of the + * comment action, tag name of the tag action. + */ + private String actionData; + + public String getResourcePath() { + return resourcePath; + } + + public void setResourcePath(String resourcePath) { + this.resourcePath = resourcePath; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public Date getDate() { + return date; + } + + public void setDate(Date date) { + this.date = date; + } + + public int getAction() { + return action; + } + + public void setAction(int action) { + this.action = action; + } + + public String getActionData() { + return actionData; + } + + public void setActionData(String actionData) { + this.actionData = actionData; + } + + public String getTitle() { + StringBuffer entryBuf = new StringBuffer(); + switch (getAction()) { + case UPDATE: + entryBuf.append("Update of "); + break; + case COMMENT: + entryBuf.append("Comment on "); + break; + case TAG: + entryBuf.append("Tag of "); + break; + case RATING: + entryBuf.append("Rating of "); + break; + default: + } + entryBuf.append(getResourcePath()); + return entryBuf.toString(); + } + + public String getText() { + StringBuffer entryBuf = new StringBuffer(); + entryBuf.append("<a href='/wso2registry/system/people/"); + entryBuf.append(getUserName()); + entryBuf.append("'>"); + entryBuf.append(getUserName()); + entryBuf.append("</a>"); + switch (getAction()) { + case UPDATE: + entryBuf.append(" updated the resource '"); + break; + case COMMENT: + entryBuf.append(" commented on the resource "); + break; + case TAG: + entryBuf.append(" tagged the resource "); + break; + case RATING: + entryBuf.append(" rated the resource "); + break; + default: + } + entryBuf.append("<a href='/wso2registry/web"); + entryBuf.append(getResourcePath()); + entryBuf.append("'>"); + entryBuf.append(getResourcePath()); + entryBuf.append("</a> on "); + entryBuf.append(getDate().toString()); + entryBuf.append("."); + return entryBuf.toString(); + } +} Added: trunk/mashup/java/modules/patches/registry/src/org/wso2/registry/jdbc/dao/AssociationDAO.java URL: http://wso2.org/svn/browse/wso2/trunk/mashup/java/modules/patches/registry/src/org/wso2/registry/jdbc/dao/AssociationDAO.java?pathrev=18987 ============================================================================== --- (empty file) +++ trunk/mashup/java/modules/patches/registry/src/org/wso2/registry/jdbc/dao/AssociationDAO.java Tue Jul 8 07:30:22 2008 @@ -0,0 +1,228 @@ +/* + * Copyright (c) 2008, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.wso2.registry.jdbc.dao; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.registry.Association; +import org.wso2.registry.exceptions.RegistryException; +import org.wso2.registry.jdbc.utils.Transaction; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; + +public class AssociationDAO { + + private static final Log log = LogFactory.getLog(AssociationDAO.class); + + public static void addAssociation(String sourcePath, + String targetPath, + String associationType) throws RegistryException { + + Connection conn = Transaction.getConnection(); + + try { + String propSQL = + "INSERT INTO ASSOCIATION (SOURCEPATH, TARGETPATH, ASSOCIATION_TYPE) VALUES (?,?,?)"; + PreparedStatement ps = conn.prepareStatement(propSQL); + ps.setString(1, sourcePath); + ps.setString(2, targetPath); + ps.setString(3, associationType); + ps.executeUpdate(); + ps.close(); + + } catch (SQLException e) { + + String msg = "Failed to add association between resources " + + sourcePath + " and " + targetPath + ". " + e.getMessage(); + log.error(msg, e); + throw new RegistryException(msg, e); + } + } + + public void removeAssociation(String sourcePath, + String targetPath, + String associationType) throws RegistryException { + + Connection conn = Transaction.getConnection(); + + try { + String propSQL = + "DELETE FROM ASSOCIATION WHERE SOURCEPATH=? AND TARGETPATH=? AND ASSOCIATION_TYPE=?"; + PreparedStatement ps = conn.prepareStatement(propSQL); + ps.setString(1, sourcePath); + ps.setString(2, targetPath); + ps.setString(3, associationType); + ps.executeUpdate(); + ps.close(); + + } catch (SQLException e) { + String msg = "Failed to remove association between resources " + + sourcePath + " and " + targetPath + ". " + e.getMessage(); + log.error(msg, e); + throw new RegistryException(msg, e); + } + } + + + public Association[] getAllAssociations(String resourcePath) throws RegistryException { + + Connection conn = Transaction.getConnection(); + + ArrayList arrayList; + try { + String propSQL = "SELECT * FROM ASSOCIATION WHERE SOURCEPATH=? OR TARGETPATH=?"; + PreparedStatement ps = conn.prepareStatement(propSQL); + ps.setString(1, resourcePath); + ps.setString(2, resourcePath); + ResultSet result = ps.executeQuery(); + arrayList = new ArrayList(); + + while (result.next()) { + Association association = new Association(); + association.setSourcePath(result.getString("SOURCEPATH")); + association.setDestinationPath(result.getString("TARGETPATH")); + association.setAssociationType(result.getString("ASSOCIATION_TYPE")); + arrayList.add(association); + } + ps.close(); + } catch (SQLException e) { + + String msg = "Failed to get all associations of resource " + + resourcePath + ". " + e.getMessage(); + log.error(msg, e); + throw new RegistryException(msg, e); + } + + Association associations[] = new Association[arrayList.size()]; + for (int i = 0; i < arrayList.size(); i++) { + associations[i] = (Association) arrayList.get(i); + } + return associations; + } + + public Association[] getAllAssociationsForType(String resourcePath, String associationType) + throws RegistryException { + Connection conn = Transaction.getConnection(); + + ArrayList arrayList; + try { + String propSQL = "SELECT SOURCEPATH, TARGETPATH FROM ASSOCIATION " + + "WHERE (SOURCEPATH=? OR TARGETPATH=?) AND ASSOCIATION_TYPE=?"; + PreparedStatement ps = conn.prepareStatement(propSQL); + ps.setString(1, resourcePath); + ps.setString(2, resourcePath); + ps.setString(3, associationType); + ResultSet result = ps.executeQuery(); + arrayList = new ArrayList(); + + while (result.next()) { + Association association = new Association(); + association.setSourcePath(result.getString("SOURCEPATH")); + association.setDestinationPath(result.getString("TARGETPATH")); + association.setAssociationType(associationType); + arrayList.add(association); + } + ps.close(); + } catch (SQLException e) { + + String msg = "Failed to get associations of type " + + associationType + " for resource " + resourcePath + ". " + e.getMessage(); + log.error(msg, e); + throw new RegistryException(msg, e); + } + + Association associations[] = new Association[arrayList.size()]; + for (int i = 0; i < arrayList.size(); i++) { + associations[i] = (Association) arrayList.get(i); + } + return associations; + } + + public void replaceAssociations(String oldPath, String newPath) throws RegistryException { + + Connection conn = Transaction.getConnection(); + + try { + String sql2 = "UPDATE ASSOCIATION SET TARGETPATH=? WHERE TARGETPATH=?"; + + PreparedStatement ps2 = conn.prepareStatement(sql2); + ps2.setString(1, newPath); + ps2.setString(2, oldPath); + ps2.executeUpdate(); + ps2.close(); + + } catch (SQLException e) { + + String msg = "Failed to replace the associations of " + oldPath + + " by reassociating them to " + newPath + ". " + e.getMessage(); + log.error(msg, e); + throw new RegistryException(msg, e); + } + } + + public void removeAllAssociations(String resourcePath) throws RegistryException { + + Connection conn = Transaction.getConnection(); + + String sql = "DELETE FROM ASSOCIATION WHERE SOURCEPATH=? OR TARGETPATH=?"; + + try { + PreparedStatement ps = conn.prepareStatement(sql); + ps.setString(1, resourcePath); + ps.setString(2, resourcePath); + ps.executeUpdate(); + ps.close(); + + } catch (SQLException e) { + + String msg = "Failed to remove associations of resource " + + resourcePath + ". " + e.getMessage(); + log.error(msg, e); + throw new RegistryException(msg, e); + } + } + + public static void copyAssociations(String fromPath ,String toPath ) throws RegistryException { + try { + Connection conn = Transaction.getConnection(); + String propSQL = "SELECT * FROM ASSOCIATION WHERE SOURCEPATH=?"; + PreparedStatement ps = conn.prepareStatement(propSQL); + ps.setString(1, fromPath); + ResultSet result = ps.executeQuery(); + ArrayList arrayList = new ArrayList(); + + while (result.next()) { + Association association = new Association(); + association.setSourcePath(toPath); + association.setDestinationPath(result.getString("TARGETPATH")); + association.setAssociationType(result.getString("ASSOCIATION_TYPE")); + arrayList.add(association); + } + + for (int i = 0; i < arrayList.size(); i++) { + Association association = (Association) arrayList.get(i); + addAssociation(toPath,association.getDestinationPath() , association.getAssociationType()); + } + } catch (SQLException e) { + e.printStackTrace(); + } + } +} _______________________________________________ Mashup-dev mailing list [email protected] http://wso2.org/cgi-bin/mailman/listinfo/mashup-dev
