Example usage for java.net URI equals

List of usage examples for java.net URI equals

Introduction

In this page you can find the example usage for java.net URI equals.

Prototype

public boolean equals(Object ob) 

Source Link

Document

Tests this URI for equality with another object.

Usage

From source file:org.dhatim.cdr.XMLConfigDigester.java

private void pushConfig(String file, URI fileURI) {
    for (SmooksConfig smooksConfig : configStack) {
        if (fileURI.equals(smooksConfig.fileURI)) {
            throw new SmooksConfigurationException("Invalid circular reference to config file '" + fileURI
                    + "' from inside config file '" + getCurrentPath() + "'.");
        }//  w  w w  . j  a  va  2s.  c  om
    }

    SmooksConfig config = new SmooksConfig(file);

    config.parent = configStack.peek();
    config.fileURI = fileURI;
    configStack.push(config);
}

From source file:org.entrystore.repository.impl.PrincipalManagerImpl.java

/**
 * Checks if the authenticated user it authorized to perform a specific task on a Entry. The task is defined by an access property.
 * @param entry the entry on which to check the specified accessProperty.
 * @param accessProperty the access property to check the entry for.
 * @throws AuthorizationException if not allowed.
 *//*from w  ww. ja  v a2s . com*/
public void checkAuthenticatedUserAuthorized(Entry entry, AccessProperty accessProperty)
        throws AuthorizationException {

    //is check authorization on?
    if (!entry.getRepositoryManager().isCheckForAuthorization()) {
        return;
    }

    URI currentUserURI = getAuthenticatedUserURI();

    //is anyone logged in on this thread?
    if (currentUserURI == null) {
        currentUserURI = getGuestUser().getURI();
        log.warn("Authenticated user not set, assuming guest user");
    }

    //is admin?
    if (currentUserURI.equals(getAdminUser().getURI())) {
        return;
    }

    //Switch to admin so that the PrincipalManager can perform all
    //neccessary checks without being hindered by itself (results in loops).
    setAuthenticatedUserURI(getAdminUser().getURI());

    try {

        //Fetch the current user from thread local.
        User currentUser = getUser(currentUserURI);

        //Check if user is in admingroup.
        if (getAdminGroup().isMember(currentUser)) {
            return;
        }

        Entry contextEntry = entry.getContext().getEntry();
        //Check if user is owner of surrounding context
        if (hasAccess(currentUser, contextEntry, AccessProperty.Administer)) {
            return;
        } else {
            //If entry overrides Context ACL (only relevant if the user is not an owner of the context)
            if (entry.hasAllowedPrincipals()) {
                if (hasAccess(currentUser, entry, accessProperty)) {
                    return;
                }
            } else {
                //Check if user has access to the surrounding context of the entry.
                if (accessProperty == AccessProperty.ReadMetadata
                        || accessProperty == AccessProperty.ReadResource) {
                    if (hasAccess(currentUser, contextEntry, AccessProperty.ReadResource)) {
                        return;
                    }
                } else {
                    if (hasAccess(currentUser, contextEntry, AccessProperty.WriteResource)) {
                        return;
                    }
                }
            }
        }

        throw new AuthorizationException(currentUser, entry, accessProperty);
    } finally {
        //Switch back to the current user.
        setAuthenticatedUserURI(currentUserURI);
    }
}

From source file:org.opencb.opencga.storage.app.cli.client.VariantCommandExecutor.java

private void stats() throws IOException, URISyntaxException, StorageManagerException, IllegalAccessException,
        InstantiationException, ClassNotFoundException {
    CliOptionsParser.StatsVariantsCommandOptions statsVariantsCommandOptions = variantCommandOptions.statsVariantsCommandOptions;

    ObjectMap options = storageConfiguration.getVariant().getOptions();
    if (statsVariantsCommandOptions.dbName != null && !statsVariantsCommandOptions.dbName.isEmpty()) {
        options.put(VariantStorageManager.Options.DB_NAME.key(), statsVariantsCommandOptions.dbName);
    }/*from  w w  w.  j a  v a2  s  . com*/
    options.put(VariantStorageManager.Options.OVERWRITE_STATS.key(),
            statsVariantsCommandOptions.overwriteStats);
    options.put(VariantStorageManager.Options.UPDATE_STATS.key(), statsVariantsCommandOptions.updateStats);
    if (statsVariantsCommandOptions.fileId != 0) {
        options.put(VariantStorageManager.Options.FILE_ID.key(), statsVariantsCommandOptions.fileId);
    }
    options.put(VariantStorageManager.Options.STUDY_ID.key(), statsVariantsCommandOptions.studyId);
    if (statsVariantsCommandOptions.studyConfigurationFile != null
            && !statsVariantsCommandOptions.studyConfigurationFile.isEmpty()) {
        options.put(FileStudyConfigurationManager.STUDY_CONFIGURATION_PATH,
                statsVariantsCommandOptions.studyConfigurationFile);
    }

    if (statsVariantsCommandOptions.commonOptions.params != null) {
        options.putAll(statsVariantsCommandOptions.commonOptions.params);
    }

    Map<String, Set<String>> cohorts = null;
    if (statsVariantsCommandOptions.cohort != null && !statsVariantsCommandOptions.cohort.isEmpty()) {
        cohorts = new LinkedHashMap<>(statsVariantsCommandOptions.cohort.size());
        for (Map.Entry<String, String> entry : statsVariantsCommandOptions.cohort.entrySet()) {
            List<String> samples = Arrays.asList(entry.getValue().split(","));
            if (samples.size() == 1 && samples.get(0).isEmpty()) {
                samples = new ArrayList<>();
            }
            cohorts.put(entry.getKey(), new HashSet<>(samples));
        }
    }

    options.put(VariantStorageManager.Options.AGGREGATED_TYPE.key(), statsVariantsCommandOptions.aggregated);

    if (statsVariantsCommandOptions.aggregationMappingFile != null) {
        Properties aggregationMappingProperties = new Properties();
        try {
            aggregationMappingProperties
                    .load(new FileInputStream(statsVariantsCommandOptions.aggregationMappingFile));
            options.put(VariantStorageManager.Options.AGGREGATION_MAPPING_PROPERTIES.key(),
                    aggregationMappingProperties);
        } catch (FileNotFoundException e) {
            logger.error("Aggregation mapping file {} not found. Population stats won't be parsed.",
                    statsVariantsCommandOptions.aggregationMappingFile);
        }
    }

    /**
     * Create DBAdaptor
     */
    VariantDBAdaptor dbAdaptor = variantStorageManager
            .getDBAdaptor(options.getString(VariantStorageManager.Options.DB_NAME.key()));
    //        dbAdaptor.setConstantSamples(Integer.toString(statsVariantsCommandOptions.fileId));    // TODO jmmut: change to studyId when we
    // remove fileId
    StudyConfiguration studyConfiguration = dbAdaptor.getStudyConfigurationManager()
            .getStudyConfiguration(statsVariantsCommandOptions.studyId, new QueryOptions(options)).first();
    if (studyConfiguration == null) {
        studyConfiguration = new StudyConfiguration(statsVariantsCommandOptions.studyId,
                statsVariantsCommandOptions.dbName);
    }
    /**
     * Create and load stats
     */
    URI outputUri = UriUtils.createUri(
            statsVariantsCommandOptions.fileName == null ? "" : statsVariantsCommandOptions.fileName);
    URI directoryUri = outputUri.resolve(".");
    String filename = outputUri.equals(directoryUri)
            ? VariantStorageManager.buildFilename(studyConfiguration.getStudyName(),
                    statsVariantsCommandOptions.fileId)
            : Paths.get(outputUri.getPath()).getFileName().toString();
    //        assertDirectoryExists(directoryUri);
    VariantStatisticsManager variantStatisticsManager = new VariantStatisticsManager();

    boolean doCreate = true;
    boolean doLoad = true;
    //        doCreate = statsVariantsCommandOptions.create;
    //        doLoad = statsVariantsCommandOptions.load != null;
    //        if (!statsVariantsCommandOptions.create && statsVariantsCommandOptions.load == null) {
    //            doCreate = doLoad = true;
    //        } else if (statsVariantsCommandOptions.load != null) {
    //            filename = statsVariantsCommandOptions.load;
    //        }

    try {

        Map<String, Integer> cohortIds = statsVariantsCommandOptions.cohortIds.entrySet().stream()
                .collect(Collectors.toMap(Map.Entry::getKey, e -> Integer.parseInt(e.getValue())));

        QueryOptions queryOptions = new QueryOptions(options);
        if (doCreate) {
            filename += "." + TimeUtils.getTime();
            outputUri = outputUri.resolve(filename);
            outputUri = variantStatisticsManager.createStats(dbAdaptor, outputUri, cohorts, cohortIds,
                    studyConfiguration, queryOptions);
        }

        if (doLoad) {
            outputUri = outputUri.resolve(filename);
            variantStatisticsManager.loadStats(dbAdaptor, outputUri, studyConfiguration, queryOptions);
        }
    } catch (Exception e) { // file not found? wrong file id or study id? bad parameters to ParallelTaskRunner?
        e.printStackTrace();
        logger.error(e.getMessage());
    }
}

From source file:org.restcomm.connect.interpreter.SmsInterpreter.java

protected URI resolve(final URI base, final URI uri) {
    if (base.equals(uri)) {
        return uri;
    } else {/* w w  w. j  a v a 2  s.  com*/
        if (!uri.isAbsolute()) {
            return base.resolve(uri);
        } else {
            return uri;
        }
    }
}

From source file:uk.org.taverna.platform.execution.impl.local.WorkflowToDataflowMapper.java

private void addActivity(ProcessorBinding processorBinding) throws EditException, ActivityNotFoundException,
        ActivityConfigurationException, InvalidWorkflowException {
    net.sf.taverna.t2.workflowmodel.Processor processor = workflowToDataflowProcessors
            .get(processorBinding.getBoundProcessor());
    Activity scufl2Activity = processorBinding.getBoundActivity();
    URI activityType = scufl2Activity.getType();
    if (!activityService.activityExists(activityType))
        throw new ActivityNotFoundException("No activity exists for " + activityType);
    Configuration configuration = scufl2Activity.getConfiguration();

    // create the activity
    net.sf.taverna.t2.workflowmodel.processor.activity.Activity<?> activity = activityService
            .createActivity(activityType, configuration.getJson());
    // check if we have a nested workflow
    if (activityType.equals(NESTED_WORKFLOW_URI)) {
        if (activity instanceof NestedDataflow) {
            Workflow nestedWorkflow = scufl2Tools
                    .nestedWorkflowForProcessor(processorBinding.getBoundProcessor(), profile);
            ((NestedDataflow) activity).setNestedDataflow(getDataflow(nestedWorkflow));
        } else//from w  w  w  .  j a  v a 2 s.  c om
            throw new ActivityConfigurationException("Activity is not an instance of NestedDataflow");
    }

    // add the activity to the processor
    edits.getAddActivityEdit(processor, activity).doEdit();

    // add input ports
    for (InputActivityPort inputActivityPort : scufl2Activity.getInputPorts()) {
        ActivityInputPort activityInputPort = edits.createActivityInputPort(inputActivityPort.getName(),
                inputActivityPort.getDepth(), false, new ArrayList<Class<? extends ExternalReferenceSPI>>(),
                String.class);
        edits.getAddActivityInputPortEdit(activity, activityInputPort).doEdit();
    }
    // add output ports
    for (OutputActivityPort outputActivityPort : scufl2Activity.getOutputPorts()) {
        ActivityOutputPort activitytOutputPort = edits.createActivityOutputPort(outputActivityPort.getName(),
                outputActivityPort.getDepth(), outputActivityPort.getGranularDepth());
        edits.getAddActivityOutputPortEdit(activity, activitytOutputPort).doEdit();
    }
    // map input ports
    for (ProcessorInputPortBinding portBinding : processorBinding.getInputPortBindings()) {
        InputProcessorPort processorPort = portBinding.getBoundProcessorPort();
        InputActivityPort activityPort = portBinding.getBoundActivityPort();
        edits.getAddActivityInputPortMappingEdit(activity, processorPort.getName(), activityPort.getName())
                .doEdit();
    }
    // map output ports
    for (ProcessorOutputPortBinding portBinding : processorBinding.getOutputPortBindings()) {
        OutputProcessorPort processorPort = portBinding.getBoundProcessorPort();
        OutputActivityPort activityPort = portBinding.getBoundActivityPort();
        edits.getAddActivityOutputPortMappingEdit(activity, processorPort.getName(), activityPort.getName())
                .doEdit();
    }
    workflowToDataflowActivities.put(scufl2Activity, activity);
    dataflowToWorkflowActivities.put(activity, scufl2Activity);
}

From source file:org.dita.dost.module.reader.AbstractReaderModule.java

/**
 * Add the given file the wait list if it has not been parsed.
 *
 * @param ref reference to absolute system path
 *//* w  w w .  jav a 2s .co m*/
void addToWaitList(final Reference ref) {
    final URI file = ref.filename;
    assert file.isAbsolute() && file.getFragment() == null;
    if (doneList.contains(file) || waitList.contains(ref) || file.equals(currentFile)) {
        return;
    }

    waitList.add(ref);
}

From source file:org.entrystore.repository.impl.PrincipalManagerImpl.java

public Set<AccessProperty> getRights(Entry entry) {
    Set<AccessProperty> set = new HashSet<AccessProperty>();
    //is check authorization on?
    if (!entry.getRepositoryManager().isCheckForAuthorization()) {
        set.add(AccessProperty.Administer);
        return set;
    }//from   ww  w .  j av  a 2s. c o  m

    URI currentUserURI = getAuthenticatedUserURI();

    //is anyone logged in on this thread?
    if (currentUserURI == null) {
        //TODO, should we perhaps assume guest if none set?
        log.error("Authenticated user not set, should at least be guest.");
        throw new AuthorizationException(null, entry, null);
    }

    //is admin?
    if (currentUserURI.equals(getAdminUser().getURI())) {
        set.add(AccessProperty.Administer);
        return set;
    }

    //Switch to admin so that the PrincipalManager can perform all
    //neccessary checks without being hindered by itself (results in loops).
    setAuthenticatedUserURI(getAdminUser().getURI());

    try {

        //Fetch the current user from thread local.
        User currentUser = getUser(currentUserURI);

        //Check if user is in admingroup.
        if (getAdminGroup().isMember(currentUser)) {
            set.add(AccessProperty.Administer);
            return set;
        }

        Entry contextEntry = entry.getContext().getEntry();
        //Check if user is owner of surrounding context
        if (hasAccess(currentUser, contextEntry, AccessProperty.Administer)) {
            set.add(AccessProperty.Administer);
        } else {
            //If entry overrides Context ACL (only relevant if the user is not an owner of the context)
            if (entry.hasAllowedPrincipals()) {
                if (hasAccess(currentUser, entry, AccessProperty.Administer)) {
                    set.add(AccessProperty.Administer);
                    return set;
                } else {
                    if (hasAccess(currentUser, entry, AccessProperty.WriteMetadata)) {
                        set.add(AccessProperty.WriteMetadata);
                    } else if (hasAccess(currentUser, entry, AccessProperty.ReadMetadata)) {
                        set.add(AccessProperty.ReadMetadata);
                    }
                    if (hasAccess(currentUser, entry, AccessProperty.WriteResource)) {
                        set.add(AccessProperty.WriteResource);
                    } else if (hasAccess(currentUser, entry, AccessProperty.ReadResource)) {
                        set.add(AccessProperty.ReadResource);
                    }
                }
            } else {
                if (hasAccess(currentUser, contextEntry, AccessProperty.WriteResource)) {
                    set.add(AccessProperty.Administer);
                } else if (hasAccess(currentUser, contextEntry, AccessProperty.ReadResource)) {
                    set.add(AccessProperty.ReadMetadata);
                    set.add(AccessProperty.ReadResource);
                }
            }
        }
    } finally {
        //Switch back to the current user.
        setAuthenticatedUserURI(currentUserURI);
    }
    return set;
}

From source file:org.wrml.runtime.rest.ApiNavigator.java

public <M extends Model> M visitLink(final Link link, final Model referrer, final URI referrerUri,
        final DimensionsBuilder dimensionsBuilder, final Model parameter) {

    if (referrer == null) {
        throw new ApiNavigatorException("The referrer cannot be null.", null, this);
    }/* w ww  .jav  a 2 s .c  om*/

    if (referrerUri == null) {
        throw new ApiNavigatorException("The referrer's Document URI cannot be null.", null, this);
    }

    if (link == null) {
        throw new ApiNavigatorException("The link cannot be null.", null, this);
    }

    final Model embeddedModel = link.getDoc();
    if (embeddedModel != null) {
        return (M) embeddedModel;
    }

    final URI referrerSchemaUri = referrer.getSchemaUri();
    final URI referenceRelationUri = link.getRel();

    final ApiLoader apiLoader = getApi().getContext().getApiLoader();
    final LinkRelation linkRelation = apiLoader.loadLinkRelation(referenceRelationUri);
    if (linkRelation == null) {
        throw new ApiNavigatorException("The link relation cannot be null.", null, this);
    }

    final Method method = linkRelation.getMethod();

    final Resource endPointResource = getEndpointResource(referenceRelationUri, referrerUri);
    if (endPointResource == null) {
        throw new ApiNavigatorException("The end point cannot be null.", null, this);
    }

    URI uri = link.getHref();

    if (uri == null) {

        uri = endPointResource.getHrefUri(referrer, referenceRelationUri);

        if (uri == null) {
            throw new ApiNavigatorException("The end point's document URI (link's href) cannot be null.", null,
                    this);
        }
    }

    final Api api = getApi();
    final Context context = api.getContext();
    final SchemaLoader schemaLoader = context.getSchemaLoader();

    final DimensionsBuilder responseDimensionsBuilder;
    if (dimensionsBuilder == null) {
        final URI responseSchemaUri = getDefaultResponseSchemaUri(method, uri);

        responseDimensionsBuilder = new DimensionsBuilder(responseSchemaUri);
    } else {
        responseDimensionsBuilder = dimensionsBuilder;
    }

    responseDimensionsBuilder.setReferrerUri(referrerUri);
    URI schemaUri = responseDimensionsBuilder.getSchemaUri();

    if (method == Method.Get && (schemaUri == null || schemaUri.equals(schemaLoader.getDocumentSchemaUri()))) {
        if (referrerUri != null && referrerUri.equals(uri)) {
            schemaUri = referrerSchemaUri;
        }
    }

    if (schemaUri != null) {
        responseDimensionsBuilder.setSchemaUri(schemaUri);
    }

    final Dimensions responseDimensions = apiLoader.buildDocumentDimensions(method, uri,
            responseDimensionsBuilder);
    final Keys keys = apiLoader.buildDocumentKeys(uri, responseDimensions.getSchemaUri());

    Set<URI> requestSchemaUris = endPointResource.getRequestSchemaUris(method);
    if (parameter != null) {
        // Determine if the parameter is allowed

        final URI parameterSchemaUri = parameter.getSchemaUri();
        if (requestSchemaUris.isEmpty()) {
            throw new ApiNavigatorException("The " + linkRelation.getUri()
                    + " does not allow any parameter to be passed to resource: " + endPointResource, null,
                    this);
        } else if (!requestSchemaUris.contains(parameterSchemaUri)) {

            boolean isParameterSubType = false;
            for (final URI requestSchemaUri : requestSchemaUris) {
                final Prototype requestPrototype = schemaLoader.getPrototype(requestSchemaUri);
                if (requestPrototype.isAssignableFrom(parameterSchemaUri)) {
                    isParameterSubType = true;
                    break;
                }
            }

            if (!isParameterSubType) {
                throw new ApiNavigatorException("The " + linkRelation.getUri() + " does not allow a "
                        + parameterSchemaUri + " parameter to be passed to resource: " + endPointResource, null,
                        this);
            }
        }
    }

    Model param = parameter;

    // Handle special case for "Save" links to enable the referrer model automatically passes itself as the parameter.
    if (method == Method.Save && param == null && (!requestSchemaUris.isEmpty())) {
        for (final URI requestSchemaUri : requestSchemaUris) {

            Class<?> requestSchemaInterface;
            try {
                requestSchemaInterface = schemaLoader.getSchemaInterface(requestSchemaUri);
            } catch (final ClassNotFoundException e) {
                throw new ApiNavigatorException(
                        "Failed to load the schema interface for: \"" + requestSchemaUri + "\"", e, this);
            }

            // Determine if the referrer may be inferred as a (this) parameter.

            Class<?> referrerSchemaInterface;
            try {
                referrerSchemaInterface = schemaLoader.getSchemaInterface(referrerSchemaUri);
            } catch (final ClassNotFoundException e) {
                throw new ApiNavigatorException("Failed to load the schema interface for referrer schema id: \""
                        + referrerSchemaUri + "\"", e, this);
            }

            if (requestSchemaInterface.isAssignableFrom(referrerSchemaInterface)) {
                /*
                 * The param was null and the referrer's type matches the link's content-type expectation, so set the referrer as the param.
                 */
                param = referrer;
                break;
            }
        }
    }

    return context.request(method, keys, responseDimensions, param);

}

From source file:org.opencb.opencga.storage.app.cli.client.executors.VariantCommandExecutor.java

private void stats() throws IOException, URISyntaxException, StorageEngineException, IllegalAccessException,
        InstantiationException, ClassNotFoundException {
    StorageVariantCommandOptions.VariantStatsCommandOptions statsVariantsCommandOptions = variantCommandOptions.statsVariantsCommandOptions;

    ObjectMap options = storageConfiguration.getVariant().getOptions();
    if (statsVariantsCommandOptions.dbName != null && !statsVariantsCommandOptions.dbName.isEmpty()) {
        options.put(VariantStorageEngine.Options.DB_NAME.key(), statsVariantsCommandOptions.dbName);
    }//from   www  . j  a v a  2  s.  c o  m
    options.put(VariantStorageEngine.Options.OVERWRITE_STATS.key(), statsVariantsCommandOptions.overwriteStats);
    options.put(VariantStorageEngine.Options.UPDATE_STATS.key(), statsVariantsCommandOptions.updateStats);
    options.putIfNotEmpty(VariantStorageEngine.Options.FILE_ID.key(), statsVariantsCommandOptions.fileId);
    options.put(VariantStorageEngine.Options.STUDY_ID.key(), statsVariantsCommandOptions.studyId);
    if (statsVariantsCommandOptions.studyConfigurationFile != null
            && !statsVariantsCommandOptions.studyConfigurationFile.isEmpty()) {
        options.put(FileStudyConfigurationManager.STUDY_CONFIGURATION_PATH,
                statsVariantsCommandOptions.studyConfigurationFile);
    }
    options.put(VariantStorageEngine.Options.RESUME.key(), statsVariantsCommandOptions.resume);

    if (statsVariantsCommandOptions.commonOptions.params != null) {
        options.putAll(statsVariantsCommandOptions.commonOptions.params);
    }

    Map<String, Set<String>> cohorts = null;
    if (statsVariantsCommandOptions.cohort != null && !statsVariantsCommandOptions.cohort.isEmpty()) {
        cohorts = new LinkedHashMap<>(statsVariantsCommandOptions.cohort.size());
        for (Map.Entry<String, String> entry : statsVariantsCommandOptions.cohort.entrySet()) {
            List<String> samples = Arrays.asList(entry.getValue().split(","));
            if (samples.size() == 1 && samples.get(0).isEmpty()) {
                samples = new ArrayList<>();
            }
            cohorts.put(entry.getKey(), new HashSet<>(samples));
        }
    }

    options.put(VariantStorageEngine.Options.AGGREGATED_TYPE.key(), statsVariantsCommandOptions.aggregated);

    if (statsVariantsCommandOptions.aggregationMappingFile != null) {
        Properties aggregationMappingProperties = new Properties();
        try {
            aggregationMappingProperties
                    .load(new FileInputStream(statsVariantsCommandOptions.aggregationMappingFile));
            options.put(VariantStorageEngine.Options.AGGREGATION_MAPPING_PROPERTIES.key(),
                    aggregationMappingProperties);
        } catch (FileNotFoundException e) {
            logger.error("Aggregation mapping file {} not found. Population stats won't be parsed.",
                    statsVariantsCommandOptions.aggregationMappingFile);
        }
    }

    /**
     * Create DBAdaptor
     */
    VariantDBAdaptor dbAdaptor = variantStorageEngine
            .getDBAdaptor(options.getString(VariantStorageEngine.Options.DB_NAME.key()));
    //        dbAdaptor.setConstantSamples(Integer.toString(statsVariantsCommandOptions.fileId));    // TODO jmmut: change to studyId when we
    // remove fileId
    StudyConfiguration studyConfiguration = dbAdaptor.getStudyConfigurationManager()
            .getStudyConfiguration(statsVariantsCommandOptions.studyId, new QueryOptions(options)).first();
    if (studyConfiguration == null) {
        studyConfiguration = new StudyConfiguration(Integer.parseInt(statsVariantsCommandOptions.studyId),
                statsVariantsCommandOptions.dbName);
    }
    /**
     * Create and load stats
     */
    URI outputUri = UriUtils.createUri(
            statsVariantsCommandOptions.fileName == null ? "" : statsVariantsCommandOptions.fileName);
    URI directoryUri = outputUri.resolve(".");
    String filename = outputUri.equals(directoryUri)
            ? VariantStorageEngine.buildFilename(studyConfiguration.getStudyName(),
                    Integer.parseInt(statsVariantsCommandOptions.fileId))
            : Paths.get(outputUri.getPath()).getFileName().toString();
    //        assertDirectoryExists(directoryUri);
    DefaultVariantStatisticsManager variantStatisticsManager = new DefaultVariantStatisticsManager(dbAdaptor);

    boolean doCreate = true;
    boolean doLoad = true;
    //        doCreate = statsVariantsCommandOptions.create;
    //        doLoad = statsVariantsCommandOptions.load != null;
    //        if (!statsVariantsCommandOptions.create && statsVariantsCommandOptions.load == null) {
    //            doCreate = doLoad = true;
    //        } else if (statsVariantsCommandOptions.load != null) {
    //            filename = statsVariantsCommandOptions.load;
    //        }

    try {

        Map<String, Integer> cohortIds = statsVariantsCommandOptions.cohortIds.entrySet().stream()
                .collect(Collectors.toMap(Map.Entry::getKey, e -> Integer.parseInt(e.getValue())));

        QueryOptions queryOptions = new QueryOptions(options);
        if (doCreate) {
            filename += "." + TimeUtils.getTime();
            outputUri = outputUri.resolve(filename);
            outputUri = variantStatisticsManager.createStats(dbAdaptor, outputUri, cohorts, cohortIds,
                    studyConfiguration, queryOptions);
        }

        if (doLoad) {
            outputUri = outputUri.resolve(filename);
            variantStatisticsManager.loadStats(dbAdaptor, outputUri, studyConfiguration, queryOptions);
        }
    } catch (Exception e) { // file not found? wrong file id or study id? bad parameters to ParallelTaskRunner?
        e.printStackTrace();
        logger.error(e.getMessage());
    }
}

From source file:org.datavec.api.records.reader.impl.LineRecordReader.java

@Override
public List<Record> loadFromMetaData(List<RecordMetaData> recordMetaDatas) throws IOException {
    //First: create a sorted list of the RecordMetaData
    List<Triple<Integer, RecordMetaDataLine, List<Writable>>> list = new ArrayList<>();
    Set<URI> uris = new HashSet<>();
    Iterator<RecordMetaData> iter = recordMetaDatas.iterator();
    int count = 0;
    while (iter.hasNext()) {
        RecordMetaData rmd = iter.next();
        if (!(rmd instanceof RecordMetaDataLine)) {
            throw new IllegalArgumentException(
                    "Invalid metadata; expected RecordMetaDataLine instance; got: " + rmd);
        }//from w  ww.  j a  v  a 2 s  . c o  m
        list.add(new Triple<>(count++, (RecordMetaDataLine) rmd, (List<Writable>) null));
        if (rmd.getURI() != null)
            uris.add(rmd.getURI());
    }
    List<URI> sortedURIs = null;
    if (uris.size() > 0) {
        sortedURIs = new ArrayList<>(uris);
        Collections.sort(sortedURIs);
    }

    //Sort by URI first (if possible - don't always have URIs though, for String split etc), then sort by line number:
    Collections.sort(list, new Comparator<Triple<Integer, RecordMetaDataLine, List<Writable>>>() {
        @Override
        public int compare(Triple<Integer, RecordMetaDataLine, List<Writable>> o1,
                Triple<Integer, RecordMetaDataLine, List<Writable>> o2) {
            if (o1.getSecond().getURI() != null) {
                if (!o1.getSecond().getURI().equals(o2.getSecond().getURI())) {
                    return o1.getSecond().getURI().compareTo(o2.getSecond().getURI());
                }
            }
            return Integer.compare(o1.getSecond().getLineNumber(), o2.getSecond().getLineNumber());
        }
    });

    if (uris.size() > 0 && sortedURIs != null) {
        //URIs case - possibly with multiple URIs
        Iterator<Triple<Integer, RecordMetaDataLine, List<Writable>>> metaIter = list.iterator(); //Currently sorted by URI, then line number

        URI currentURI = sortedURIs.get(0);
        Iterator<String> currentUriIter = IOUtils
                .lineIterator(new InputStreamReader(currentURI.toURL().openStream()));
        int currentURIIdx = 0; //Index of URI
        int currentLineIdx = 0; //Index of the line for the current URI
        String line = currentUriIter.next();
        while (metaIter.hasNext()) {
            Triple<Integer, RecordMetaDataLine, List<Writable>> t = metaIter.next();
            URI thisURI = t.getSecond().getURI();
            int nextLineIdx = t.getSecond().getLineNumber();

            //First: find the right URI for this record...
            while (!currentURI.equals(thisURI)) {
                //Iterate to the next URI
                currentURIIdx++;
                if (currentURIIdx >= sortedURIs.size()) {
                    //Should never happen
                    throw new IllegalStateException(
                            "Count not find URI " + thisURI + " in URIs list: " + sortedURIs);
                }
                currentURI = sortedURIs.get(currentURIIdx);
                currentLineIdx = 0;
                if (currentURI.equals(thisURI)) {
                    //Found the correct URI for this MetaData instance
                    closeIfRequired(currentUriIter);
                    currentUriIter = IOUtils
                            .lineIterator(new InputStreamReader(currentURI.toURL().openStream()));
                    line = currentUriIter.next();
                }
            }

            //Have the correct URI/iter open -> scan to the required line
            while (currentLineIdx < nextLineIdx && currentUriIter.hasNext()) {
                line = currentUriIter.next();
                currentLineIdx++;
            }
            if (currentLineIdx < nextLineIdx && !currentUriIter.hasNext()) {
                throw new IllegalStateException("Could not get line " + nextLineIdx + " from URI " + currentURI
                        + ": has only " + currentLineIdx + " lines");
            }
            t.setThird(Collections.<Writable>singletonList(new Text(line)));
        }
    } else {
        //Not URI based: String split, etc
        Iterator<String> iterator = getIterator(0);
        Iterator<Triple<Integer, RecordMetaDataLine, List<Writable>>> metaIter = list.iterator();
        int currentLineIdx = 0;
        String line = iterator.next();
        while (metaIter.hasNext()) {
            Triple<Integer, RecordMetaDataLine, List<Writable>> t = metaIter.next();
            int nextLineIdx = t.getSecond().getLineNumber();
            while (currentLineIdx < nextLineIdx && iterator.hasNext()) {
                line = iterator.next();
                currentLineIdx++;
            }
            t.setThird(Collections.<Writable>singletonList(new Text(line)));
        }
        closeIfRequired(iterator);
    }

    //Now, sort by the original (request) order:
    Collections.sort(list, new Comparator<Triple<Integer, RecordMetaDataLine, List<Writable>>>() {
        @Override
        public int compare(Triple<Integer, RecordMetaDataLine, List<Writable>> o1,
                Triple<Integer, RecordMetaDataLine, List<Writable>> o2) {
            return Integer.compare(o1.getFirst(), o2.getFirst());
        }
    });

    //And return...
    List<Record> out = new ArrayList<>();
    for (Triple<Integer, RecordMetaDataLine, List<Writable>> t : list) {
        out.add(new org.datavec.api.records.impl.Record(t.getThird(), t.getSecond()));
    }
    return out;
}