Skip to content

Commit

Permalink
Merge pull request #89 from elvisisking/artifact-command-sramp
Browse files Browse the repository at this point in the history
Upgraded to S-RAMP 0.1.0. Created new artifact types for VDB objects. Made commands cancelable. Worked related to artifact relationships.
  • Loading branch information
elvisisking committed Jan 31, 2013
2 parents 772092d + 20027a8 commit 1c8af8b
Show file tree
Hide file tree
Showing 42 changed files with 1,298 additions and 544 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 Expand Up @@ -129,6 +143,23 @@ public static void notNull(final Object objectBeingChecked,
}
}

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

if (collection.length != expected) {
throw new IllegalArgumentException(I18n.bind(CommonI18n.objectIsNull, identifier));
}
}

/**
* Don't allow construction.
*/
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 @@ -12,7 +12,7 @@
import org.komodo.common.util.HashCode;
import org.komodo.common.util.Precondition;
import org.komodo.common.util.StringUtil;
import org.komodo.repository.artifact.Artifact.Type;
import org.komodo.repository.artifact.VdbArtifact;
import org.komodo.repository.deriver.DeriverUtil;
import org.overlord.sramp.client.SrampAtomApiClient;
import org.overlord.sramp.client.SrampClientQuery;
Expand Down Expand Up @@ -61,15 +61,17 @@ public AtomRepositoryManager(final String url,
/**
* {@inheritDoc}
*
* @see org.komodo.repository.RepositoryManager#addVdb(java.io.InputStream, java.lang.String)
* @see org.komodo.repository.RepositoryManager#addVdb(java.io.InputStream)
*/
@Override
public BaseArtifactType addVdb(final InputStream content,
final String fileName) throws Exception {
final ArtifactType artifact = ArtifactType.valueOf(Type.VDB.getName());
LOGGER.debug("RepositoryManager:Adding VDB with file name '{}'", fileName); //$NON-NLS-1$
final BaseArtifactType newArtifact = this.client.uploadArtifact(artifact, content, fileName);
LOGGER.debug("RepositoryManager:VDB artifact with name '{}' was created", newArtifact.getName()); //$NON-NLS-1$
public BaseArtifactType addVdb(final InputStream content) throws Exception {
final ArtifactType artifact = ArtifactType.valueOf(VdbArtifact.TYPE.getId());
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 '{}' 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 @@ -7,6 +7,7 @@
*/
package org.komodo.repository;

import org.komodo.repository.artifact.Artifact.RelationshipType;

/**
* Constants used when working with the S-RAMP database and Teiid artifacts.
Expand All @@ -28,6 +29,23 @@ public interface Sramp {
*/
String DOCUMENT_ARTIFACT_PATH = ROOT_PATH + "/core/Document"; //$NON-NLS-1$

/**
* A relationship between a derived artifact and the document artifact. This is created by S-RAMP deriver framework.
*/
RelationshipType RELATED_DOCUMENT_RELATIONSHIP = new RelationshipType() {

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

};

/**
* The root node path in the S-RAMP database for user-defined artifacts. Value is {@value}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,13 @@ public class QuerySettings {

/**
* Adds a VDB to the repository. Caller should set additional artifact properties based on the VDB business object created
* from this artifact. Caller should ensure stream is closed. The file name is used to determine mime type.
* from this artifact. Caller should ensure stream is closed.
*
* @param content the resource content (cannot be <code>null</code>)
* @param fileName the file name associated with the content (cannot be <code>null</code> or empty)
* @return the artifact (never <code>null</code>)
* @throws Exception if there is a problem creating the artifact in the repository
*/
BaseArtifactType addVdb(final InputStream content,
final String fileName) throws Exception;
BaseArtifactType addVdb(final InputStream content) throws Exception;

/**
* @param uuid the UUID of the artifact being requested (cannot be <code>null</code> or empty)
Expand Down Expand Up @@ -103,6 +101,13 @@ BaseArtifactType addVdb(final InputStream content,
*/
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

0 comments on commit 1c8af8b

Please sign in to comment.