Class ImportService

  • All Implemented Interfaces:
    Destroyable

    public class ImportService
    extends Object
    implements Destroyable
    Main entry point for the import framework. Instead of calling the different importer implementations, the ImportService should be called instead. This class contains the same methods as the other implementations, but has an extra parameter URL. This URL should be the same identifier that is returned by the "getImportSource" method that is defined in the importer implementation you want to use.
    Author:
    Roeland Dillen (roeland at atmire dot com)
    • Constructor Detail

      • ImportService

        public ImportService()
        Constructs an empty ImportService class object
    • Method Detail

      • setImportSources

        @Autowired(required=false)
        public void setImportSources​(List<MetadataSource> importSources)
                              throws MetadataSourceException
        Sets the importsources that will be used to delegate the retrieving and matching of records to
        Parameters:
        importSources - A list of MetadataSource to set to this service
        Throws:
        MetadataSourceException - if the underlying methods throw any exception.
      • getImportSources

        protected Map<String,​MetadataSource> getImportSources()
        Retrieve the importSources set to this class.
        Returns:
        An unmodifiableMap of importSources
      • matchingImports

        protected Collection<MetadataSource> matchingImports​(String uri)
        Utility method to find what import implementations match the imports uri.
        Parameters:
        uri - the identifier of the import implementation or * for all
        Returns:
        matching MetadataSource implementations
      • findMatchingRecords

        public Collection<ImportRecord> findMatchingRecords​(String uri,
                                                            Item item)
                                                     throws MetadataSourceException
        Finds records based on an item Delegates to one or more MetadataSource implementations based on the uri. Results will be aggregated.
        Parameters:
        uri - the identifier of the import implementation or * for all
        item - an item to base the search on
        Returns:
        a collection of import records. Only the identifier of the found records may be put in the record.
        Throws:
        MetadataSourceException - if the underlying methods throw any exception.
      • findMatchingRecords

        public Collection<ImportRecord> findMatchingRecords​(String uri,
                                                            Query query)
                                                     throws MetadataSourceException
        Finds records based on query object. Delegates to one or more MetadataSource implementations based on the uri. Results will be aggregated.
        Parameters:
        uri - the identifier of the import implementation or * for all
        query - a query object to base the search on. The implementation decides how the query is interpreted.
        Returns:
        a collection of import records. Only the identifier of the found records may be put in the record.
        Throws:
        MetadataSourceException - if the underlying methods throw any exception.
      • getNbRecords

        public int getNbRecords​(String uri,
                                String query)
                         throws MetadataSourceException
        Find the number of records matching a string query;
        Parameters:
        uri - the identifier of the import implementation or * for all
        query - a query to base the search on
        Returns:
        the sum of the matching records over all import sources
        Throws:
        MetadataSourceException - if the underlying methods throw any exception.
      • getNbRecords

        public int getNbRecords​(String uri,
                                Query query)
                         throws MetadataSourceException
        Find the number of records matching a query;
        Parameters:
        uri - the identifier of the import implementation or * for all
        query - a query object to base the search on The implementation decides how the query is interpreted.
        Returns:
        the sum of the matching records over all import sources
        Throws:
        MetadataSourceException - if the underlying methods throw any exception.
      • getRecords

        public Collection<ImportRecord> getRecords​(String uri,
                                                   String query,
                                                   int start,
                                                   int count)
                                            throws MetadataSourceException
        Find the number of records matching a string query. Supports pagination
        Parameters:
        uri - the identifier of the import implementation or * for all
        query - a query object to base the search on. The implementation decides how the query is interpreted.
        start - offset to start at
        count - number of records to retrieve.
        Returns:
        a set of records. Fully transformed.
        Throws:
        MetadataSourceException - if the underlying methods throw any exception.
      • getRecords

        public Collection<ImportRecord> getRecords​(String uri,
                                                   Query query)
                                            throws MetadataSourceException
        Find the number of records matching a object query.
        Parameters:
        uri - the identifier of the import implementation or * for all
        query - a query object to base the search on. The implementation decides how the query is interpreted.
        Returns:
        a set of records. Fully transformed.
        Throws:
        MetadataSourceException - if the underlying methods throw any exception.
      • getRecord

        public ImportRecord getRecord​(String uri,
                                      String id)
                               throws MetadataSourceException
        Get a single record from a source. The first match will be returned
        Parameters:
        uri - uri the identifier of the import implementation or * for all
        id - identifier for the record
        Returns:
        a matching record
        Throws:
        MetadataSourceException - if the underlying methods throw any exception.
      • getRecord

        public ImportRecord getRecord​(String uri,
                                      Query query)
                               throws MetadataSourceException
        Get a single record from the source. The first match will be returned
        Parameters:
        uri - uri the identifier of the import implementation or * for all
        query - a query matching a single record
        Returns:
        a matching record
        Throws:
        MetadataSourceException - if the underlying methods throw any exception.
      • getImportUrls

        public Collection<String> getImportUrls()
        Retrieve the importUrls that are set on the importSources .
        Returns:
        a Collection of string, representing the configured importUrls