当前位置: 首页>>代码示例>>Java>>正文


Java ContextUtils类代码示例

本文整理汇总了Java中eu.unifiedviews.helpers.dpu.context.ContextUtils的典型用法代码示例。如果您正苦于以下问题:Java ContextUtils类的具体用法?Java ContextUtils怎么用?Java ContextUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ContextUtils类属于eu.unifiedviews.helpers.dpu.context包,在下文中一共展示了ContextUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadGraphStatements

import eu.unifiedviews.helpers.dpu.context.ContextUtils; //导入依赖的package包/类
/**
 * Read all the statements in the given graph
 * @param graphUri URI of the graph
 * @throws DPUException
 */
private void loadGraphStatements(final URI graphUri) throws DPUException {
    faultTolerance.execute(rdfInput, new FaultTolerance.ConnectionAction() {
        @Override
        public void action(RepositoryConnection connection) throws Exception {
            RepositoryResult<Statement> repositoryResult = connection.getStatements(null, null, null, false, graphUri);
            try {
                rdfStringWriter.flush();
                rdfWriter.startRDF();
                while (repositoryResult.hasNext()) {
                    if (ctx.canceled()) {
                        throw ContextUtils.dpuExceptionCancelled(ctx);
                    }
                    rdfWriter.handleStatement(repositoryResult.next());
                }
                rdfWriter.endRDF();
            } catch (RDFHandlerException e) {
                throw new DPUException("Encountered an exception when parsing RDF statements from graph: " + graphUri.stringValue(), e);
            }
        }
    });
}
 
开发者ID:poolparty-team,项目名称:PP-UnifiedViews-Plugins,代码行数:27,代码来源:RdfHttpLoader.java

示例2: loadGraphStatements

import eu.unifiedviews.helpers.dpu.context.ContextUtils; //导入依赖的package包/类
/**
 * Read all the statements in the given graph
 * @param graphUri URI of the graph
 * @throws DPUException
 */
private void loadGraphStatements(final URI graphUri) throws DPUException {
    graphStatements = new HashSet<>();
    faultTolerance.execute(rdfInput, new FaultTolerance.ConnectionAction() {
        @Override
        public void action(RepositoryConnection connection) throws Exception {
            RepositoryResult<Statement> repositoryResult = connection.getStatements(null, null, null, false, graphUri);
            graphStatements.clear();
            while (repositoryResult.hasNext()) {
                if (ctx.canceled()) {
                    throw ContextUtils.dpuExceptionCancelled(ctx);
                }
                graphStatements.add(repositoryResult.next());
            }

        }
    });
}
 
开发者ID:poolparty-team,项目名称:PP-UnifiedViews-Plugins,代码行数:23,代码来源:ConceptExtractor.java

示例3: loadFilenameUriMappings

import eu.unifiedviews.helpers.dpu.context.ContextUtils; //导入依赖的package包/类
/**
 * Read filename to URI mappings from the given graph
 * @param graphUri URI of the graph
 * @throws DPUException
 */
private void loadFilenameUriMappings(final URI graphUri) throws DPUException {
    filenameUriMappings = new HashMap<>();
    faultTolerance.execute(rdfInput, new FaultTolerance.ConnectionAction() {
        @Override
        public void action(RepositoryConnection connection) throws Exception {
            RepositoryResult<Statement> repositoryResult = connection.getStatements(null, null, null, false, graphUri);
            filenameUriMappings.clear();
            while (repositoryResult.hasNext()) {
                if (ctx.canceled()) {
                    throw ContextUtils.dpuExceptionCancelled(ctx);
                }
                Statement filenameStmt = repositoryResult.next();
                filenameUriMappings.put(filenameStmt.getObject().stringValue(), filenameStmt.getSubject().stringValue());
            }

        }
    });
}
 
开发者ID:poolparty-team,项目名称:PP-UnifiedViews-Plugins,代码行数:24,代码来源:ConceptExtractor.java

示例4: zipFiles

import eu.unifiedviews.helpers.dpu.context.ContextUtils; //导入依赖的package包/类
/**
 * Pack files in given iterator into zip file and add metadata.
 *
 * @param zipFile
 * @param filesIteration
 */
private void zipFiles(File zipFile, List<FilesDataUnit.Entry> filesIteration) throws DPUException {
    final byte[] buffer = new byte[8196];
    // Used to publish the error mesage only for the first time.
    boolean firstFailure = true;
    try (FileOutputStream fos = new FileOutputStream(zipFile); ZipOutputStream zos = new ZipOutputStream(fos)) {
        // Itarate over files and zip them.
        int counter = 0;
        for (FilesDataUnit.Entry entry : filesIteration) {
            LOG.info("Processing: {}/{}", counter++, filesIteration.size());
            if (ctx.canceled()) {
                break;
            }
            if (!addZipEntry(zos, buffer, entry)) {
                if (firstFailure) {
                    // TODO This needs rework, we fail but not instantly?
                    ContextUtils.sendError(ctx, "zipper.errors.zip.failed", "");
                }
                firstFailure = false;
            }
        }
    } catch (IOException ex) {
        throw new DPUException(ex);
    }
}
 
开发者ID:UnifiedViews,项目名称:Plugins,代码行数:31,代码来源:Zipper.java

示例5: XsltExecutor

import eu.unifiedviews.helpers.dpu.context.ContextUtils; //导入依赖的package包/类
public XsltExecutor(XsltConfig_V2 config,
        BlockingQueue<Task> taskQueue, FaultTolerance faultTolerance, UserExecContext ctx,
        Integer totalFileCounter)
        throws DPUException {
    LOG.info("New executor created!");
    this.proc = new Processor(false);
    // register UUID extension function
    proc.registerExtensionFunction(UUIDGenerator.getInstance());
    this.compiler = proc.newXsltCompiler();
    try {
        this.executable = compiler.compile(
                new StreamSource(new StringReader(config.getXsltTemplate())));
    } catch (SaxonApiException ex) {
        throw ContextUtils.dpuException(ctx, ex, "xslt.dpu.executor.errors.xsltCompile");
    }
    this.config = config;
    this.taskQueue = taskQueue;
    this.ctx = ctx;
    this.totalFileCounter = totalFileCounter;
}
 
开发者ID:UnifiedViews,项目名称:Plugins,代码行数:21,代码来源:XsltExecutor.java

示例6: checkGraph

import eu.unifiedviews.helpers.dpu.context.ContextUtils; //导入依赖的package包/类
protected void checkGraph(RepositoryConnection connection, final List<RDFDataUnit.Entry> entries) throws DPUException {

        SparqlUtils.SparqlAskObject ask = null;
        try {
            ask = SparqlUtils.createAsk(config.getAskQuery(), entries);
            SparqlUtils.execute(connection, ask);
        } catch (RepositoryException | MalformedQueryException | UpdateExecutionException | QueryEvaluationException | SparqlProblemException | DataUnitException e) {
            throw new DPUException(e.getLocalizedMessage(), e);
        }

        if (!ask.result) {
            reportFailure();
        }
        else {
            //everything OK:
            ContextUtils.sendShortInfo(ctx, "rdfvalidation.finished.ok");
        }

    }
 
开发者ID:UnifiedViews,项目名称:Plugins,代码行数:20,代码来源:SparqlAsk.java

示例7: getScriptWithPath

import eu.unifiedviews.helpers.dpu.context.ContextUtils; //导入依赖的package包/类
private String getScriptWithPath() throws DPUException {
    DPUContext dpuContext = ctx.getExecMasterContext().getDpuContext();
    Map<String, String> environment = dpuContext.getEnvironment();

    String pathToScript = environment.get(SHELL_SCRIPT_PATH);
    if (pathToScript == null || pathToScript.trim().equals("")) {
        LOG.error("Directory with shell scripts is not set in beckend configuration file!");
        throw ContextUtils.dpuException(ctx, "errors.pathToScriptsNotSet.backend");
    }
    File scriptDirFile = new File(pathToScript);
    if (!scriptDirFile.exists()) {
        LOG.error(String.format("Directory with shell scripts %s doesn't exist!", pathToScript));
        throw ContextUtils.dpuException(ctx, "errors.pathToScriptsDoesntExist.backend");
    }
    File scriptFile = new File(pathToScript, config.getScriptName());
    if (scriptFile == null || !scriptFile.exists()) {
        LOG.error(String.format("Script %s doesn't exist!", config.getScriptName()));
        throw ContextUtils.dpuException(ctx, "errors.scriptDoesntExist");
    }
    return scriptFile.getAbsolutePath();
}
 
开发者ID:UnifiedViews,项目名称:Plugins,代码行数:22,代码来源:ExecuteShellScript.java

示例8: innerExecute

import eu.unifiedviews.helpers.dpu.context.ContextUtils; //导入依赖的package包/类
@Override
protected void innerExecute() throws DPUException {
    if (useDataset()) {
        ContextUtils.sendShortInfo(ctx, "SparqlConstruct.execute.openrdfMode");
    } else {
        ContextUtils.sendShortInfo(ctx, "SparqlConstruct.execute.virtuosoMode");
    }
    // Update query ie. substitute constract with insert.
    String query = config.getQuery();
    if (query == null || query.isEmpty()) {
        throw ContextUtils.dpuException(ctx, "SparqlConstruct.execute.exception.emptyQuery");
    }
    // Modify query - we always do inserts.
    query = query.replaceFirst("(?i)CONSTRUCT", "INSERT");
    // Get graphs.
    final List<RDFDataUnit.Entry> sourceEntries = getInputEntries(rdfInput);
    // Execute.
    executeUpdateQuery(query, sourceEntries);
}
 
开发者ID:UnifiedViews,项目名称:Plugins,代码行数:20,代码来源:SparqlConstruct.java

示例9: prepareUsingClause

import eu.unifiedviews.helpers.dpu.context.ContextUtils; //导入依赖的package包/类
/**
 * @param entries
 *            List of entries to use.
 * @return Using clause for SPARQL insert, based on input graphs.
 * @throws DPUException
 */
protected String prepareUsingClause(final List<RDFDataUnit.Entry> entries) throws DPUException {
    return faultTolerance.execute(new FaultTolerance.ActionReturn<String>() {

        @Override
        public String action() throws Exception {
            final StringBuilder usingClause = new StringBuilder();
            for (RDFDataUnit.Entry entry : entries) {
                usingClause.append("USING <");
                try {
                    usingClause.append(entry.getDataGraphURI().stringValue());
                } catch (DataUnitException ex) {
                    throw ContextUtils.dpuException(ctx, ex, "SparqlConstruct.execute.exception.internal");
                }
                usingClause.append("> \n");
            }
            return usingClause.toString();
        }

    });
}
 
开发者ID:UnifiedViews,项目名称:Plugins,代码行数:27,代码来源:SparqlConstruct.java

示例10: generateGraphFile

import eu.unifiedviews.helpers.dpu.context.ContextUtils; //导入依赖的package包/类
/**
 * Check if file graph should be generated and if so, then generate new graph file.
 * 
 * @param rdfFile
 * @param graphName
 *            Name of the graph, that will be written into .graph file.
 * @throws DPUException
 */
private void generateGraphFile(final FilesDataUnit.Entry rdfFile, String graphName) throws DPUException {
    final FilesDataUnit.Entry graphFileEntry = faultTolerance.execute(new FaultTolerance.ActionReturn<FilesDataUnit.Entry>() {

        @Override
        public FilesDataUnit.Entry action() throws Exception {
            final String rdfFilePath = MetadataUtils.get(inRdfData, rdfFile, FilesVocabulary.UV_VIRTUAL_PATH);
            return FilesDataUnitUtils.createFile(outFilesData, rdfFilePath + ".graph");
        }
    });
    try {
        FileUtils.writeStringToFile(FaultToleranceUtils.asFile(faultTolerance, graphFileEntry), graphName);
    } catch (IOException ex) {
        throw ContextUtils.dpuException(ctx, ex, "rdfToFiles.error.graphFile");
    }
}
 
开发者ID:UnifiedViews,项目名称:Plugins,代码行数:24,代码来源:RdfToFiles.java

示例11: innerExecute

import eu.unifiedviews.helpers.dpu.context.ContextUtils; //导入依赖的package包/类
@Override
protected void innerExecute() throws DPUException {

    ContextUtils.sendShortInfo(ctx, "ExcelToCsv.message");

    try {
        sheetNameSet = new TreeSet<>(String.CASE_INSENSITIVE_ORDER); // case-insensitive sheet names
        String sheetNames = config.getSheetNames();
        if (sheetNames != null && sheetNames.length() > 0) {
            sheetNameSet.addAll(Arrays.asList(sheetNames.split(Pattern.quote(":"))));
        }

        Set<FilesDataUnit.Entry> entries = FilesHelper.getFiles(input);
        for (FilesDataUnit.Entry entry : entries) {
            excelToCsv(entry);
        }
    } catch (DataUnitException | EncryptedDocumentException | InvalidFormatException | IOException ex) {
        throw ContextUtils.dpuException(ctx, ex, "ExcelToCsv.dpuFailed");
    }
}
 
开发者ID:UnifiedViews,项目名称:Plugins,代码行数:21,代码来源:ExcelToCsv.java

示例12: afterInit

import eu.unifiedviews.helpers.dpu.context.ContextUtils; //导入依赖的package包/类
@Override
public void afterInit(Context context) {
    this.context = context;
    if (context instanceof ExecContext) {
        this.dpuContext = ((ExecContext) context).getDpuContext();
        LOG.debug("\tcontext set to: {}", this.dpuContext);
    }
    // Load configuration.
    try {
        this.config = context.getConfigManager().get(USED_CONFIG_NAME, configHistory);
    } catch (ConfigException ex) {
        LOG.warn("Can't load configuration.", ex);
        ContextUtils.sendInfo(context.asUserContext(), "Addon failed to load configuration",
                "Failed to load configuration for: {0} default configuration is used.", ADDON_NAME);
        this.config = new Configuration_V1();
    }
    if (this.config == null) {
        ContextUtils.sendInfo(context.asUserContext(), "Addon failed to load configuration",
                "Failed to load configuration for: {0} default configuration is used.", ADDON_NAME);
        this.config = new Configuration_V1();
    }
    // Add exception for Virtuoso
    this.config.exceptionNames.add("java.sql.BatchUpdateException");
    // Virtuoso Communications Link Failure (timeout) : Connection to the server lost
    this.config.exceptionNames.add("virtuoso.jdbc4.VirtuosoException");
}
 
开发者ID:UnifiedViews,项目名称:Plugin-DevEnv,代码行数:27,代码来源:FaultTolerance.java

示例13: executeAddons

import eu.unifiedviews.helpers.dpu.context.ContextUtils; //导入依赖的package包/类
/**
 * Execute all {@link ExecutableAddon}s of this DPU.
 *
 * @param execPoint
 * @return If exception is thrown then return false.
 */
private boolean executeAddons(Extension.ExecutionPoint execPoint) {
    boolean result = true;
    for (Extension item : this.masterContext.getExtensions()) {
        if (item instanceof Extension.Executable) {
            final Extension.Executable executable = (Extension.Executable) item;
            try {
                LOG.debug("Executing '{}' with on '{}' point", executable.getClass().getSimpleName(),
                        execPoint.toString());
                executable.execute(execPoint);
            } catch (ExtensionException ex) {
                ContextUtils.sendError(this.ctx, "Addon execution failed",
                        ex, "Addon: s", item.getClass().getSimpleName());
                result = false;
            }
        }
    }
    return result;
}
 
开发者ID:UnifiedViews,项目名称:Plugin-DevEnv,代码行数:25,代码来源:AbstractDpu.java

示例14: requestExtractionModelUpdateService

import eu.unifiedviews.helpers.dpu.context.ContextUtils; //导入依赖的package包/类
/**
 * Check and refresh extraction model of the PoolParty project
 * @param wrapper Wrapped HTTP state used for requests
 */
private void requestExtractionModelUpdateService(HttpStateWrapper wrapper) {
    try {
        String modelStatus = null;
        String requestUrl = config.getExtractionModelServiceUrl() + "/" + config.getProjectId();
        HttpGet httpGet = new HttpGet(requestUrl);
        CloseableHttpResponse response = wrapper.client.execute(wrapper.host, httpGet, wrapper.context);
        int status = response.getStatusLine().getStatusCode();
        if (status == HttpStatus.SC_OK) {
            modelStatus = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
        }
        response.close();

        if (modelStatus != null && modelStatus.contains("\"upToDate\" : true")) {
            LOG.info("Extraction model is up-to-date");
            return;
        } else {
            LOG.info("Start to update extraction model because its status is unknown");
            requestUrl = requestUrl + "/refresh";
            httpGet = new HttpGet(requestUrl);
            response = wrapper.client.execute(wrapper.host, httpGet, wrapper.context);
            status = response.getStatusLine().getStatusCode();
            if (status != HttpStatus.SC_OK) {
                ContextUtils.sendShortInfo(ctx, "Extraction model update failed, extraction result may be outdated");
                LOG.warn("Extraction model update failed, extraction result may be outdated");
            }
        }
    } catch (Exception e) {
        LOG.warn("Encountered an exception when requesting extraction model update service", e);
    }
}
 
开发者ID:poolparty-team,项目名称:PP-UnifiedViews-Plugins,代码行数:35,代码来源:ConceptExtractor.java

示例15: createOutputGraph

import eu.unifiedviews.helpers.dpu.context.ContextUtils; //导入依赖的package包/类
/**
 * Creates new output graph. Symbolic name is completely new (using time stamp in suffix).
 * Data graph IRI is generated.
 * @return New output graph.
 * @throws DPUException
 */
protected IRI createOutputGraph() throws DPUException {
    // Register new output graph
    final String symbolicName = "http://unifiedviews.eu/resource/sparql-construct/"
            + Long.toString((new Date()).getTime());
    try {
        return rdfOutput.addNewDataGraph(symbolicName);
    } catch (DataUnitException ex) {
        throw ContextUtils.dpuException(ctx, ex, "sparqlUpdate.dpu.error.cantAddGraph");
    }
}
 
开发者ID:UnifiedViews,项目名称:Plugins,代码行数:17,代码来源:SparqlUpdate.java


注:本文中的eu.unifiedviews.helpers.dpu.context.ContextUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。