/// ***************** New generation interface **********************
/**
- * Removes the specified content item and all content stored under the given item.
+ * Removes the specified content item and if the item is a container or directory,
+ * all content stored under the given item.
*
* @param item the item.
* @throws ItemNotFoundException if the item cannot be found
* @throws ItemNotFoundException if the specified coordinates cannot be found in the repository
* @throws ContentAccessException if the access to the underlying storage failed
*/
- List<? extends Artifact> getAllArtifacts( ItemSelector selector) throws ContentAccessException;
+ List<? extends Artifact> getArtifacts( ItemSelector selector) throws ContentAccessException;
/**
* Returns the artifacts that match the given selector. It is up to the repository implementation
* @throws ItemNotFoundException if the specified coordinates cannot be found in the repository
* @throws ContentAccessException if the access to the underlying storage failed
*/
- Stream<? extends Artifact> getAllArtifactStream( ItemSelector selector) throws ContentAccessException;
+ Stream<? extends Artifact> getArtifactStream( ItemSelector selector) throws ContentAccessException;
/**
*/
List<? extends Artifact> getArtifacts( ContentItem item) throws ContentAccessException;
- /**
- * Return all the artifacts of a given namespace and all sub namespaces that are defined under the
- * given namespace.
- *
- * @param namespace the namespace, which is the parent namespace
- * @param recurse <code>true</code>, if all sub namespaces should be searched too, otherwise <code>false</code>
- * @return a list of artifacts or a empty list, if no artifacts are available for the specified namespace
- */
- List<? extends Artifact> getArtifacts( Namespace namespace, boolean recurse ) throws ContentAccessException;
-
-
/**
* Return a stream of artifacts that are part of the given content item. The returned stream is
* auto closable. There is no guarantee about the order of returned artifacts.
Stream<? extends Artifact> getArtifactStream( ContentItem item ) throws ContentAccessException;
- /**
- * Return a stream of all artifacts that are available for the given namespace and its sub namespaces. The artifacts
- * are retrieved recursively. There is no guarantee about the order of returned artifacts.
- *
- * As the stream may access IO resources, you should always use call this method inside try-with-resources or
- * make sure, that the stream is closed after using it.
- *
- * @param namespace the namespace from where the artifacts should be returned
- * @param recurse <code>true</code>, if all sub namespaces should be searched too, otherwise <code>false</code>
- * @return a stream of artifacts. The stream is auto closable. You should always make sure, that the stream
- * is closed after use.
- */
- Stream<? extends Artifact> getArtifactStream( Namespace namespace, boolean recurse ) throws ContentAccessException;
-
-
/**
* Returns true, if the selector coordinates point to a existing item in the repository.
*
public interface ItemSelector
{
- String getProjectId( );
-
+ /**
+ * Selects the namespace to search for. You can use the {@link #searchSubNamespaces()} flag
+ * to decide, if only the given namespace or the namespace and all sub namespaces (if they exist) should be
+ * queried. If empty, the root namespace is searched.
+ * @return the namespace to search
+ */
String getNamespace( );
+ /**
+ * Selects the project id to search for. If empty all projects are searched.
+ * @return the project id
+ */
+ String getProjectId( );
+
+ /**
+ * Selects the version to search for. If empty all versions are searched.
+ * @return the version
+ */
String getVersion( );
+ /**
+ * Selects a specific artifact version. This may be different from the version, e.g.
+ * for SNAPSHOT versions. If empty, the artifact version will be ignored.
+ * @return the artifact version or empty string
+ */
String getArtifactVersion( );
+ /**
+ * Returns the artifact id to search for. If empty, all artifacts are returned.
+ * @return the artifact id or a empty string
+ */
String getArtifactId( );
+ /**
+ * Returns the type to search for. If empty, the type is ignored.
+ * @return the type or a empty string.
+ */
String getType( );
+ /**
+ * Returns the classifier string used for querying, or empty string if no classifier.
+ * If it returns a '*' than all classifiers should be selected.
+ * @return the classifier string
+ */
String getClassifier( );
+ /**
+ * Returns the attribute to search for or <code>null</code>, if the
+ * attribute key should not be used for search.
+ * @param key the attribute key
+ * @return
+ */
String getAttribute( String key );
+ /**
+ * The extension of the file/asset.
+ * @return
+ */
String getExtension( );
+ /**
+ * The map of attributes to search for
+ * @return
+ */
Map<String, String> getAttributes( );
+ /**
+ * Returns <code>true</code>, if not only the given namespace but all sub namespaces
+ * of the given namespace should be queried too.
+ */
+ boolean searchSubNamespaces();
+
+ /**
+ * <code>true</code>, if all files/assets should be returned that match the given selector,
+ * or <code>false</code>, if only the main assets should be returned.
+ * Related assets are e.g. hash files or signature files.
+ * @return <code>true</code>, if all assets should be found otherwise <code>false</code>
+ */
+ boolean findRelatedArtifacts();
+
default boolean hasNamespace( )
{
return !StringUtils.isEmpty( getNamespace( ) );
}
@Override
- public List<? extends Artifact> getAllArtifacts( ItemSelector selector ) throws ContentAccessException
+ public List<? extends Artifact> getArtifacts( ItemSelector selector ) throws ContentAccessException
{
return null;
}
@Override
- public Stream<? extends Artifact> getAllArtifactStream( ItemSelector selector ) throws ContentAccessException
+ public Stream<? extends Artifact> getArtifactStream( ItemSelector selector ) throws ContentAccessException
{
return null;
}
}
@Override
- public List<? extends Artifact> getAllArtifacts( ItemSelector selector ) throws ContentAccessException
+ public List<? extends Artifact> getArtifacts( ItemSelector selector ) throws ContentAccessException
{
return null;
}
@Override
- public Stream<? extends Artifact> getAllArtifactStream( ItemSelector selector ) throws ContentAccessException
+ public Stream<? extends Artifact> getArtifactStream( ItemSelector selector ) throws ContentAccessException
{
return null;
}
}
@Override
- public List<? extends Artifact> getAllArtifacts( ItemSelector selector ) throws ContentAccessException
+ public List<? extends Artifact> getArtifacts( ItemSelector selector ) throws ContentAccessException
{
return null;
}
@Override
- public Stream<? extends Artifact> getAllArtifactStream( ItemSelector selector ) throws ContentAccessException
+ public Stream<? extends Artifact> getArtifactStream( ItemSelector selector ) throws ContentAccessException
{
return null;
}
*/
private Predicate<StorageAsset> getFileFilterFromSelector(final ItemSelector selector) {
Predicate<StorageAsset> p = a -> a.isLeaf( );
+ StringBuilder fileNamePattern = new StringBuilder("^" );
if (selector.hasArtifactId()) {
- final String pattern = selector.getArtifactId( );
- p = p.and( a -> StringUtils.startsWithIgnoreCase( a.getName( ), pattern ) );
+ fileNamePattern.append( Pattern.quote(selector.getArtifactId( )) ).append("-");
+ } else {
+ fileNamePattern.append("[A-Za-z0-9_\\-.]+-");
}
if (selector.hasArtifactVersion()) {
- final String pattern = selector.getArtifactVersion( );
- p = p.and( a -> StringUtils.containsIgnoreCase( a.getName( ), pattern ) );
+ fileNamePattern.append( Pattern.quote(selector.getArtifactVersion( )) );
+ } else {
+ fileNamePattern.append( "[A-Za-z0-9_\\-.]+" );
}
- if (selector.hasExtension()) {
- final String pattern = "."+selector.getExtension( );
- p = p.and( a -> StringUtils.endsWithIgnoreCase( a.getName( ), pattern ) );
- } else if (selector.hasType()) {
- final String pattern = "."+ MavenContentHelper.getArtifactExtension( selector );
- p = p.and( a -> StringUtils.endsWithIgnoreCase( a.getName( ), pattern ) );
+ String classifier = selector.hasClassifier( ) ? selector.getClassifier( ) :
+ ( selector.hasType( ) ? MavenContentHelper.getClassifierFromType( selector.getType( ) ) : null );
+ if (classifier != null)
+ {
+ if ( "*".equals( classifier ) )
+ {
+ fileNamePattern.append( "-[A-Za-z0-9]+\\." );
+ }
+ else
+ {
+ fileNamePattern.append("-").append( Pattern.quote( classifier ) ).append( "\\." );
+ }
+ } else {
+ fileNamePattern.append( "\\." );
}
- if (selector.hasClassifier()) {
- final String pattern = "-" + selector.getClassifier( ) + ".";
- p = p.and( a -> StringUtils.containsIgnoreCase( a.getName( ), pattern ) );
- } else if (selector.hasType()) {
- final String pattern = "-" + MavenContentHelper.getClassifierFromType( selector.getType( ) ) + ".";
- p = p.and( a -> StringUtils.containsIgnoreCase( a.getName( ).toLowerCase( ), pattern ) );
+ String extension = selector.hasExtension( ) ? selector.getExtension( ) :
+ ( selector.hasType( ) ? MavenContentHelper.getArtifactExtension( selector ) : null );
+ if (extension != null) {
+ fileNamePattern.append( Pattern.quote( extension ) );
+ } else {
+ fileNamePattern.append( ".*" );
}
- return p;
- }
-
- /*
- TBD
- */
- @Override
- public List<? extends Artifact> getAllArtifacts( ItemSelector selector ) throws ContentAccessException
- {
- return null;
+ final Pattern pattern = Pattern.compile( fileNamePattern.toString() );
+ return p.and( a -> pattern.matcher( a.getName( ) ).matches());
}
- /*
- TBD
- */
- @Override
- public Stream<? extends Artifact> getAllArtifactStream( ItemSelector selector ) throws ContentAccessException
- {
- return null;
- }
- /*
- TBD
+ /**
+ * Returns all the subdirectories of the given namespace directory as project.
*/
@Override
public List<? extends Project> getProjects( Namespace namespace )
{
- return null;
+ return namespace.getAsset( ).list( ).stream( )
+ .filter( a -> a.isContainer( ) )
+ .map( a -> getProjectFromArtifactPath( a ) )
+ .collect( Collectors.toList());
}
@Override
public List<? extends Project> getProjects( ItemSelector selector ) throws ContentAccessException, IllegalArgumentException
{
- return null;
+ return getProjects( getNamespace( selector ) );
}
/**
}
}
+
/*
- TBD
- */
+ TBD
+ */
@Override
- public List<? extends Artifact> getArtifacts( ContentItem item )
+ public List<? extends Artifact> getArtifacts( ItemSelector selector ) throws ContentAccessException
{
return null;
}
TBD
*/
@Override
- public List<? extends Artifact> getArtifacts( Namespace namespace, boolean recurse )
+ public Stream<? extends Artifact> getArtifactStream( ItemSelector selector ) throws ContentAccessException
{
return null;
}
/*
- TBD
- */
+ TBD
+ */
@Override
- public Stream<? extends Artifact> getArtifactStream( ContentItem item )
+ public List<? extends Artifact> getArtifacts( ContentItem item )
{
return null;
}
+
/*
TBD
*/
@Override
- public Stream<? extends Artifact> getArtifactStream( Namespace namespace, boolean recurse )
+ public Stream<? extends Artifact> getArtifactStream( ContentItem item )
{
return null;
}
- /*
- TBD
+ /**
+ * Checks, if the asset/file queried by the given selector exists.
*/
@Override
public boolean hasContent( ItemSelector selector )
{
- return false;
+ return getItem( selector ).getAsset( ).exists( );
}
/*