Skip to content

Commit

Permalink
Upgraded to using s-ramp 0.1.0. Made the commands cancelable in the h…
Browse files Browse the repository at this point in the history
…ope that the GUI could also use them.

Created a relationship on VdbArtifact so that it knows what its derived artifacts are. Refactored relationship
definitions to their specific artifact type.
  • Loading branch information
elvisisking committed Jan 31, 2013
1 parent 071feb9 commit 20027a8
Show file tree
Hide file tree
Showing 30 changed files with 753 additions and 288 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
*/
public class CollectionUtil {

/**
* @param collection the collection being checked (can be <code>null</code> or empty)
* @return <code>true</code> if <code>null</code> or empty
*/
public static boolean isEmpty(final Collection<?> collection) {
return ((collection == null) || collection.isEmpty());
}

/**
* @param map the map being checked (can be <code>null</code> or empty)
* @return <code>true</code> if <code>null</code> or empty
Expand All @@ -26,11 +34,11 @@ public static boolean isEmpty(final Map<?, ?> map) {
}

/**
* @param collection the collection being checked (can be <code>null</code> or empty)
* @param array the array being checked (can be <code>null</code> or empty)
* @return <code>true</code> if <code>null</code> or empty
*/
public static boolean isEmpty(final Collection<?> collection) {
return ((collection == null) || collection.isEmpty());
public static boolean isEmpty(final Object[] array) {
return ((array == null) || (array.length == 0));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,20 @@ public static void matchesExactly(final String actual,
}
}

/**
* @param collectionBeingChecked the collection being checked (can be <code>null</code> or empty)
* @param identifier the identifier used in the error message (cannot be <code>null</code> or empty)
* @throws IllegalArgumentException if the collection is <code>null</code> or empty
*/
public static void notEmpty(final Object[] collectionBeingChecked,
final String identifier) {
assert !StringUtil.isEmpty(identifier) : "identifier cannot be empty"; //$NON-NLS-1$

if (CollectionUtil.isEmpty(collectionBeingChecked)) {
throw new IllegalArgumentException(I18n.bind(CommonI18n.collectionIsEmpty, identifier));
}
}

/**
* @param collectionBeingChecked the collection being checked (can be <code>null</code> or empty)
* @param identifier the identifier used in the error message (cannot be <code>null</code> or empty)
Expand Down
43 changes: 41 additions & 2 deletions komodo-common/src/main/java/org/komodo/common/util/StringUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,54 @@
public class StringUtil {

/**
* A empty string constant.
* The default delimiter used when combining strings. Value is {@value}.
*/
public static final String EMPTY_STRING = ""; //$NON-NLS-1$
public static final String DEFAULT_DELIMITER = ","; //$NON-NLS-1$

/**
* A empty string array constant.
*/
public static final String[] EMPTY_ARRAY = {};

/**
* A empty string constant.
*/
public static final String EMPTY_STRING = ""; //$NON-NLS-1$

/**
* @param strings the strings being joined (cannot be <code>null</code> or empty)
* @return a string combining all input values separated by the default delimiter
*/
public static String createDelimitedString(final String... strings) {
return createDelimitedString(DEFAULT_DELIMITER, strings);
}

/**
* @param delimiter the string to use to separate the values (cannot be <code>null</code> or empty)
* @param strings the strings being joined (cannot be <code>null</code> or empty)
* @return a string combining all input values separated by the specified delimiter
*/
public static String createDelimitedString(final String delimiter,
final String... strings) {
Precondition.notEmpty(delimiter, "delimiter"); //$NON-NLS-1$
Precondition.notEmpty(strings, "strings"); //$NON-NLS-1$

final StringBuilder result = new StringBuilder();
boolean firstTime = true;

for (final String string : strings) {
if (firstTime) {
firstTime = false;
} else {
result.append(delimiter);
}

result.append(string);
}

return result.toString();
}

/**
* @param text the string being checked (can be <code>null</code> or empty)
* @return <code>true</code> if <code>null</code> or empty
Expand Down
29 changes: 20 additions & 9 deletions komodo-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,11 @@
<junit.version>4.10</junit.version>
<komodo.java.version>1.6</komodo.java.version>
<log4j.version>1.2.16</log4j.version>
<modeshape.version>3.1.0.Final</modeshape.version>
<resteasy.version>2.3.4.Final</resteasy.version>
<slf4j.api.version>1.6.1</slf4j.api.version>
<slf4j.log4j.version>1.6.1</slf4j.log4j.version>
<s-ramp.version>0.0.3-SNAPSHOT</s-ramp.version>
<s-ramp.version>0.1.0-SNAPSHOT</s-ramp.version>
</properties>

<dependencyManagement>
Expand All @@ -98,6 +99,14 @@
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.komodo</groupId>
<artifactId>komodo-common</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.komodo</groupId>
<artifactId>komodo-teiid</artifactId>
Expand Down Expand Up @@ -146,30 +155,32 @@

<dependency>
<groupId>org.overlord.sramp</groupId>
<artifactId>s-ramp-repository-jcr</artifactId>
<artifactId>s-ramp-repository-jcr-modeshape</artifactId>
<version>${s-ramp.version}</version>
<classifier>tests</classifier>
</dependency>

<dependency>
<groupId>org.overlord.sramp</groupId>
<artifactId>s-ramp-atom</artifactId>
<artifactId>s-ramp-server</artifactId>
<version>${s-ramp.version}</version>
<classifier>classes</classifier>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.overlord.sramp</groupId>
<artifactId>s-ramp-server</artifactId>
<artifactId>s-ramp-shell-api</artifactId>
<version>${s-ramp.version}</version>
<classifier>classes</classifier>
<scope>test</scope>
</dependency>

<!--
ModeShape
-->
<dependency>
<groupId>org.overlord.sramp</groupId>
<artifactId>s-ramp-shell</artifactId>
<version>${s-ramp.version}</version>
<groupId>org.modeshape</groupId>
<artifactId>modeshape-jcr</artifactId>
<version>${modeshape.version}</version>
</dependency>

<!--
Expand Down
17 changes: 7 additions & 10 deletions komodo-repository/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
<dependency>
<groupId>org.komodo</groupId>
<artifactId>komodo-common</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>

<dependency>
Expand All @@ -51,16 +49,15 @@

<dependency>
<groupId>org.overlord.sramp</groupId>
<artifactId>s-ramp-atom</artifactId>
<classifier>classes</classifier>
</dependency>

<dependency>
<groupId>org.overlord.sramp</groupId>
<artifactId>s-ramp-repository-jcr</artifactId>
<artifactId>s-ramp-repository-jcr-modeshape</artifactId>
<classifier>tests</classifier>
</dependency>
</dependency>

<dependency>
<groupId>org.modeshape</groupId>
<artifactId>modeshape-jcr</artifactId>
</dependency>

<dependency>
<groupId>org.overlord.sramp</groupId>
<artifactId>s-ramp-server</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ public BaseArtifactType addVdb(final InputStream content) throws Exception {
artifact.setMimeType("application/xml"); //$NON-NLS-1$
LOGGER.debug("RepositoryManager:Adding VDB ..."); //$NON-NLS-1$
final BaseArtifactType newArtifact = this.client.uploadArtifact(artifact, content, null);
LOGGER.debug("RepositoryManager:VDB artifact with name '{}' was created", newArtifact.getName()); //$NON-NLS-1$
LOGGER.debug("RepositoryManager:VDB artifact with name '{}' and UUID '{}' was created", //$NON-NLS-1$
newArtifact.getName(),
newArtifact.getUuid());
return newArtifact;
}

Expand Down Expand Up @@ -100,7 +102,7 @@ public boolean equals(final Object obj) {
@Override
public BaseArtifactType get(final String uuid) throws Exception {
Precondition.notEmpty(uuid, "uuid"); //$NON-NLS-1$
final QueryResultSet result = this.client.query(DeriverUtil.getUuidQueryString(uuid));
final QueryResultSet result = query(DeriverUtil.getUuidQueryString(uuid));

if (result.size() == 1) {
final ArtifactSummary summary = result.get(0);
Expand All @@ -120,7 +122,7 @@ public QueryResultSet getDerivedArtifacts(final BaseArtifactType artifact) throw
Precondition.notNull(artifact, "artifact"); //$NON-NLS-1$
LOGGER.debug("RepositoryManager:Getting derived artifacts using query: '{}'", //$NON-NLS-1$
DeriverUtil.getDerivedArtifactsQueryString(artifact.getUuid()));
return this.client.query(DeriverUtil.getDerivedArtifactsQueryString(artifact.getUuid()));
return query(DeriverUtil.getDerivedArtifactsQueryString(artifact.getUuid()));
}

/**
Expand Down Expand Up @@ -194,6 +196,16 @@ public QueryResultSet query(final QuerySettings settings) throws Exception {
return clientQuery.query();
}

/**
* {@inheritDoc}
*
* @see org.komodo.repository.RepositoryManager#query(java.lang.String)
*/
@Override
public QueryResultSet query(String statement) throws Exception {
Precondition.notNull(statement, "statement"); //$NON-NLS-1$
return this.client.query(statement);
}
/**
* {@inheritDoc}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ public class QuerySettings {
*/
QueryResultSet query(final QuerySettings settings) throws Exception;

/**
* @param srampQuery the query statement (cannot be <code>null</code> or empty)
* @return the query results containing the artifacts (never <code>null</code>)
* @throws Exception if there is a problem running query
*/
QueryResultSet query(final String srampQuery) throws Exception;

/**
* @param newName the new name of the repository manager (can be <code>null</code> or empty)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.UUID;
import org.komodo.common.util.Precondition;
import org.s_ramp.xmlns._2010.s_ramp.BaseArtifactEnum;
import org.s_ramp.xmlns._2010.s_ramp.BaseArtifactType;
import org.s_ramp.xmlns._2010.s_ramp.ExtendedArtifactType;

/**
Expand All @@ -21,7 +22,7 @@ public class ArtifactFactory {
* @param artifactType the type of the artifact to create (cannot be <code>null</code>)
* @return the created artifact (never <code>null</code>)
*/
public static ExtendedArtifactType create(final Artifact.Type artifactType) {
public static BaseArtifactType create(final Artifact.Type artifactType) {
Precondition.notNull(artifactType, "artifactType"); //$NON-NLS-1$

final ExtendedArtifactType artifact = new ExtendedArtifactType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public class DataPolicyArtifact implements Artifact {

/**
* A relationship between a data policy and its permissions.
* A relationship between a data policy artifact and its permission artifacts.
*/
public static final RelationshipType PERMISSIONS_RELATIONSHIP = new RelationshipType() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public class PermissionArtifact implements Artifact {

/**
* A relationship between a permission and its data policy.
* A relationship between a permission artifact and its data policy artifact.
*/
public static final RelationshipType DATA_POLICY_RELATIONSHIP = new RelationshipType() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public class SchemaArtifact implements Artifact {

/**
* A relationship between a schema/model and its sources.
* A relationship between a schema/model artifact and its source artifacts.
*/
public static final RelationshipType SOURCES_RELATIONSHIP = new RelationshipType() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public class SourceArtifact implements Artifact {

/**
* A relationship between a source and its schema/model.
* A relationship between a source artifact and its schema/model artifact.
*/
public static final RelationshipType SCHEMA_RELATIONSHIP = new RelationshipType() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,28 @@
*/
package org.komodo.repository.artifact;


/**
* A VDB artifact.
*/
public class VdbArtifact implements Artifact {

/**
* A relationship between a VDB artifact and its derived artifacts.
*/
public static final RelationshipType DERIVED_RELATIONSHIP = new RelationshipType() {

/**
* {@inheritDoc}
*
* @see org.komodo.repository.artifact.Artifact.RelationshipType#getId()
*/
@Override
public String getId() {
return "VdbDerivedArtifacts"; //$NON-NLS-1$
}

};

/**
* The S-RAMP artifact type for a VDB artifact.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,24 @@ public class DeriverUtil implements RepositoryConstants {
private static final String UUID_QUERY_PATTERN = Sramp.ROOT_PATH + "[@uuid = '%s']"; //$NON-NLS-1$

/**
* Creates the relationships if necessary.
* Creates a one way relationship. Creates the relationship instance if necessary.
*
* @param sourceArtifact the artifact where the relationship starts (cannot be <code>null</code>)
* @param targetArtifact the artifact where the relationship ends (cannot be <code>null</code>)
* @param relationshipType the relationship type (cannot be <code>null</code>)
*/
public static void addRelationship(final BaseArtifactType sourceArtifact,
final BaseArtifactType targetArtifact,
final Artifact.RelationshipType relationshipType) {
Precondition.notNull(sourceArtifact, "sourceArtifact"); //$NON-NLS-1$
Precondition.notNull(targetArtifact, "targetArtifact"); //$NON-NLS-1$
Precondition.notNull(relationshipType, "relationshipType"); //$NON-NLS-1$

SrampModelUtils.addGenericRelationship(sourceArtifact, relationshipType.getId(), targetArtifact.getUuid());
}

/**
* Creates a two way relationship. Creates the relationship instance if necessary.
*
* @param sourceArtifact the artifact where the relationship starts (cannot be <code>null</code>)
* @param targetArtifact the artifact where the relationship ends (cannot be <code>null</code>)
Expand Down

0 comments on commit 20027a8

Please sign in to comment.