// Path: opennms-pris-api/src/main/java/org/opennms/pris/api/Source.java
// public interface Source {
// 
//     /**
//      * Factory interface for creating {@link Source}s.
//      */
//     public static interface Factory {
//         
//         /**
//          * Returns the identifier used to created a source using this factory.
//          * 
//          * @return the identifier string
//          */
//         String getIdentifier();
// 
//         /**
//          * Creates a source.
//          * 
//          * @param config the configuration used to build the source
//          * 
//          * @return the created source
//          */
//         Source create(final InstanceConfiguration config);
//     }
// 
//     /**
//      * Loads some information and returns them.
//      *
//      * There is no requirement to the returned object as long as there is a
//      * mapper available for mapping this data.
//      *
//      * @return the loaded information
//      *
//      * @throws Exception
//      */
//     Object dump() throws Exception;
// }
// 
// Path: opennms-pris-api/src/main/java/org/opennms/pris/api/Mapper.java
// public interface Mapper {
// 
//     /**
//      * Factory interface for creating {@link Mapper}s.
//      */
//     interface Factory {
// 
//         /**
//          * Returns the identifier used to created a mapper using this factory.
//          *
//          * @return the identifier string
//          */
//         String getIdentifier();
// 
//         /**
//          * Creates a mapper.
//          *
//          * @param config the configuration used to build the mapper
//          *
//          * @return the created mapper
//          */
//         Mapper create(final InstanceConfiguration config);
//     }
// 
//     /**
//      * Maps information to a requisition.
//      *
//      * The passed data is the data returned by the source implementation.
//      *
//      * @param data the information used to create the requisition.
//      *
//      * @param requisition Requisition already filled by a mapper, or an empty requisition.
//      *
//      * @return the mapped requisition
//      *
//      * @throws Exception
//      */
//     Requisition map(final Object data,
//                     final Requisition requisition) throws Exception;
// }
// 
// Path: opennms-pris-api/src/main/java/org/opennms/pris/api/InstanceConfiguration.java
// public interface InstanceConfiguration extends Configuration {
//    
//     /**
//      * Returns the identifier of the instance.
//      * 
//      * @return the identifier string
//      */
//     String getInstanceIdentifier();
//     
//     /**
//      * Return a decorator Configuration containing every key from the current
//      * Configuration that starts with the specified prefix.
//      * 
//      * The prefix is removed from the keys in the subset.
//      * 
//      * Since the subset is a decorator and not a modified copy of the initial
//      * Configuration, any change made to the subset is available to the
//      * Configuration, and reciprocally.
//      *
//      * @param prefix The prefix used to select the properties
//      * 
//      * @return a subset configuration
//      */
//     InstanceConfiguration subset(final String prefix);
// }


import org.opennms.pris.model.Requisition;
import org.opennms.pris.api.InstanceConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.opennms.pris.api.Source;
import org.opennms.pris.api.Mapper;
import java.util.HashMap;
import java.util.Map;
import java.util.ServiceLoader;
     * Generates a requisition.
     *
     * @param instance of the requisition
     * @return the generated requisition
     *
     * @throws Exception
     */
    public Requisition generate(String instance) throws Exception {

        // Get the data from the source
        final Object data = this.source.dump();
        
        // Create the requisition to fill
        Requisition requisition = new Requisition();
        requisition.setForeignSource(instance);

        // Map the data to a requisition with the configured mapper
        requisition = this.mapper.map(data, requisition);
        
        // If the script mapper is available, an additional run of the script
        // mapper is supported after the main mapper has finished
        // TODO: Obosolete with new config language
        if (MAPPERS.containsKey("script")) {
            final InstanceConfiguration config = this.config.subset("script");
            if (!config.isEmpty()) {
                final Mapper mapper = MAPPERS.get("script").create(config);
                requisition = mapper.map(data, requisition);
            }
        }

// Path: opennms-pris-api/src/main/java/org/opennms/pris/api/Source.java
// public interface Source {
// 
//     /**
//      * Factory interface for creating {@link Source}s.
//      */
//     public static interface Factory {
//         
//         /**
//          * Returns the identifier used to created a source using this factory.
//          * 
//          * @return the identifier string
//          */
//         String getIdentifier();
// 
//         /**
//          * Creates a source.
//          * 
//          * @param config the configuration used to build the source
//          * 
//          * @return the created source
//          */
//         Source create(final InstanceConfiguration config);
//     }
// 
//     /**
//      * Loads some information and returns them.
//      *
//      * There is no requirement to the returned object as long as there is a
//      * mapper available for mapping this data.
//      *
//      * @return the loaded information
//      *
//      * @throws Exception
//      */
//     Object dump() throws Exception;
// }
// 
// Path: opennms-pris-api/src/main/java/org/opennms/pris/api/Mapper.java
// public interface Mapper {
// 
//     /**
//      * Factory interface for creating {@link Mapper}s.
//      */
//     interface Factory {
// 
//         /**
//          * Returns the identifier used to created a mapper using this factory.
//          *
//          * @return the identifier string
//          */
//         String getIdentifier();
// 
//         /**
//          * Creates a mapper.
//          *
//          * @param config the configuration used to build the mapper
//          *
//          * @return the created mapper
//          */
//         Mapper create(final InstanceConfiguration config);
//     }
// 
//     /**
//      * Maps information to a requisition.
//      *
//      * The passed data is the data returned by the source implementation.
//      *
//      * @param data the information used to create the requisition.
//      *
//      * @param requisition Requisition already filled by a mapper, or an empty requisition.
//      *
//      * @return the mapped requisition
//      *
//      * @throws Exception
//      */
//     Requisition map(final Object data,
//                     final Requisition requisition) throws Exception;
// }
// 
// Path: opennms-pris-api/src/main/java/org/opennms/pris/api/InstanceConfiguration.java
// public interface InstanceConfiguration extends Configuration {
//    
//     /**
//      * Returns the identifier of the instance.
//      * 
//      * @return the identifier string
//      */
//     String getInstanceIdentifier();
//     
//     /**
//      * Return a decorator Configuration containing every key from the current
//      * Configuration that starts with the specified prefix.
//      * 
//      * The prefix is removed from the keys in the subset.
//      * 
//      * Since the subset is a decorator and not a modified copy of the initial
//      * Configuration, any change made to the subset is available to the
//      * Configuration, and reciprocally.
//      *
//      * @param prefix The prefix used to select the properties
//      * 
//      * @return a subset configuration
//      */
//     InstanceConfiguration subset(final String prefix);
// }


// Path: opennms-pris-main/src/main/java/org/opennms/pris/RequisitionGenerator.java
import org.opennms.pris.model.Requisition;
import org.opennms.pris.api.InstanceConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.opennms.pris.api.Source;
import org.opennms.pris.api.Mapper;
import java.util.HashMap;
import java.util.Map;
import java.util.ServiceLoader;

     * Generates a requisition.
     *
     * @param instance of the requisition
     * @return the generated requisition
     *
     * @throws Exception
     */
    public Requisition generate(String instance) throws Exception {

        // Get the data from the source
        final Object data = this.source.dump();
        
        // Create the requisition to fill
        Requisition requisition = new Requisition();
        requisition.setForeignSource(instance);

        // Map the data to a requisition with the configured mapper
        requisition = this.mapper.map(data, requisition);
        
        // If the script mapper is available, an additional run of the script
        // mapper is supported after the main mapper has finished
        // TODO: Obosolete with new config language
        if (MAPPERS.containsKey("script")) {
            final InstanceConfiguration config = this.config.subset("script");
            if (!config.isEmpty()) {
                final Mapper mapper = MAPPERS.get("script").create(config);
                requisition = mapper.map(data, requisition);
            }
        }

        return requisition;