Examples of LDPathException


Examples of org.apache.stanbol.contenthub.servicesapi.ldpath.LDPathException

                    program.getBytes(Constants.DEFAULT_ENCODING)), Constants.DEFAULT_ENCODING);
        } catch (UnsupportedEncodingException e) {
            String msg = String.format("Encoding %s should be supported by the system",
                Constants.DEFAULT_ENCODING);
            logger.error(msg, e);
            throw new LDPathException(msg, e);
        }
    }
View Full Code Here

Examples of org.apache.stanbol.contenthub.servicesapi.ldpath.LDPathException

    private Program<Object> getLDPathProgram(String ldPathProgram) throws LDPathException {
        if (ldPathProgram == null || ldPathProgram.isEmpty()) {
            String msg = "LDPath Program cannot be null.";
            logger.error(msg);
            throw new LDPathException(msg);
        }
        RDFBackend<Object> rdfBackend = new SiteManagerBackend(referencedSiteManager);
        RdfPathParser<Object> LDparser = new RdfPathParser<Object>(rdfBackend, constructReader(ldPathProgram));
        Program<Object> program = null;
        try {
            program = LDparser.parseProgram();
        } catch (ParseException e) {
            String msg = "Cannot parse LDPath Program";
            logger.error(msg, e);
            throw new LDPathException(msg, e);
        }
        return program;
    }
View Full Code Here

Examples of org.apache.stanbol.contenthub.servicesapi.ldpath.LDPathException

        try {
            tarOutputStream = (TarArchiveOutputStream) asf.createArchiveOutputStream("tar", out);
        } catch (ArchiveException e) {
            String msg = "Cannot create an empty tar archive";
            logger.error(msg, e);
            throw new LDPathException(msg, e);
        }

        try {
            InputStream is = getSolrTemplateStream();
            ZipArchiveInputStream zis = new ZipArchiveInputStream(is);
            ZipArchiveEntry ze = null;
            byte[] schemaFile = null;
            while ((ze = zis.getNextZipEntry()) != null) {
                if (SOLR_TEMPLATE_SCHEMA.equals(ze.getName())) {
                    schemaFile = createSchemaXML(getLDPathProgram(ldPathProgram), IOUtils.toByteArray(zis));
                    TarArchiveEntry te = new TarArchiveEntry(coreName + SOLR_SCHEMA);
                    te.setSize(schemaFile.length);
                    tarOutputStream.putArchiveEntry(te);
                    tarOutputStream.write(schemaFile);
                    tarOutputStream.closeArchiveEntry();
                } else {
                    TarArchiveEntry te = new TarArchiveEntry(ze.getName().replaceAll(SOLR_TEMPLATE_NAME,
                        coreName));
                    te.setSize(ze.getSize());
                    tarOutputStream.putArchiveEntry(te);
                    tarOutputStream.write(IOUtils.toByteArray(zis));
                    tarOutputStream.closeArchiveEntry();
                }

            }
            if (schemaFile == null) {
                throw new LDPathException("Schema template ZIP should include: " + SOLR_TEMPLATE_SCHEMA);
            }
            tarOutputStream.finish();
            tarOutputStream.close();
        } catch (IOException e) {
            logger.error("", e);
            throw new LDPathException(e);
        }

        ArchiveInputStream ret;
        try {
            ret = asf.createArchiveInputStream(new ByteArrayInputStream(out.toByteArray()));
        } catch (ArchiveException e) {
            String msg = "Cannot create a final tar archive while creating an ArchiveInputStream to create a Solr core";
            logger.error(msg, e);
            throw new LDPathException(msg, e);
        }
        return ret;
    }
View Full Code Here

Examples of org.apache.stanbol.contenthub.servicesapi.ldpath.LDPathException

        try {
            is = resource != null ? resource.openStream() : null;
        } catch (IOException e) {
            String msg = "Cannot open input stream on URL resource gathered from bundle.getEntry()";
            logger.error(msg, e);
            throw new LDPathException(msg, e);
        }
        if (is == null) {
            String msg = "Solr Template ZIP cannot be found in:" + templateZip;
            logger.error(msg);
            throw new LDPathException(msg);
        }
        return is;
    }
View Full Code Here

Examples of org.apache.stanbol.contenthub.servicesapi.ldpath.LDPathException

            document = DocumentBuilderFactory.newInstance().newDocumentBuilder()
                    .parse(new ByteArrayInputStream(template));
        } catch (SAXException e) {
            String msg = e.getMessage();
            logger.error(msg, e);
            throw new LDPathException(msg, e);
        } catch (IOException e) {
            String msg = e.getMessage();
            logger.error(msg, e);
            throw new LDPathException(msg, e);
        } catch (ParserConfigurationException e) {
            String msg = e.getMessage();
            logger.error(msg, e);
            throw new LDPathException(msg, e);
        }

        Element schemaNode = document.getDocumentElement();
        NodeList fieldsNodeList = schemaNode.getElementsByTagName("fields");
        if (fieldsNodeList.getLength() != 1) {
            throw new LDPathException("Template is an invalid SOLR schema. It should be a valid a byte array");
        }

        Node fieldsNode = fieldsNodeList.item(0);

        for (FieldMapping<?,Object> fieldMapping : program.getFields()) {
            String fieldName = fieldMapping.getFieldName();
            String solrType = getSolrFieldType(fieldMapping.getFieldType());

            if (solrType == null) {
                logger.error("field {} has an invalid field type; ignoring field definition", fieldName);
            } else {
                Element fieldElement = document.createElement("field");
                fieldElement.setAttribute("name", fieldName);
                fieldElement.setAttribute("type", solrType);
                fieldElement.setAttribute("stored", "true");
                fieldElement.setAttribute("indexed", "true");
                fieldElement.setAttribute("multiValued", "true");

                // Handle extra field configuration
                final Map<String,String> fieldConfig = fieldMapping.getFieldConfig();
                if (fieldConfig != null) {
                    for (String attr : fieldConfig.keySet()) {
                        if (SOLR_FIELD_OPTIONS.contains(attr)) {
                            fieldElement.setAttribute(attr, fieldConfig.get(attr));
                        }
                    }
                }
                fieldsNode.appendChild(fieldElement);

                if (fieldConfig != null && fieldConfig.keySet().contains(SOLR_COPY_FIELD_OPTION)) {
                    String[] copyFields = fieldConfig.get(SOLR_COPY_FIELD_OPTION).split(",\\s*");
                    for (String copyField : copyFields) {
                        Element copyElement = document.createElement("copyField");
                        copyElement.setAttribute("source", fieldName);
                        copyElement.setAttribute("dest", copyField);
                        schemaNode.appendChild(copyElement);
                    }
                } else {
                    Element copyElement = document.createElement("copyField");
                    copyElement.setAttribute("source", fieldName);
                    copyElement.setAttribute("dest", SOLR_ALLTEXT_FIELD);
                    schemaNode.appendChild(copyElement);
                }
            }
        }

        DOMImplementationRegistry registry;
        try {
            registry = DOMImplementationRegistry.newInstance();
        } catch (ClassCastException e) {
            String msg = e.getMessage();
            logger.error(msg, e);
            throw new LDPathException(msg, e);
        } catch (ClassNotFoundException e) {
            String msg = e.getMessage();
            logger.error(msg, e);
            throw new LDPathException(msg, e);
        } catch (InstantiationException e) {
            String msg = e.getMessage();
            logger.error(msg, e);
            throw new LDPathException(msg, e);
        } catch (IllegalAccessException e) {
            String msg = e.getMessage();
            logger.error(msg, e);
            throw new LDPathException(msg, e);
        }

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DOMImplementationLS lsImpl = (DOMImplementationLS) registry.getDOMImplementation("LS");
        LSSerializer lsSerializer = lsImpl.createLSSerializer();
View Full Code Here

Examples of org.apache.stanbol.contenthub.servicesapi.ldpath.LDPathException

        if (!managedProgramsDir.exists()) {
            if (managedProgramsDir.mkdirs()) {
                logger.info("Directory for programs created succesfully");
            } else {
                logger.error("Directory for programs COULD NOT be created");
                throw new LDPathException("Directory : " + managedProgramsDir.getAbsolutePath()
                                          + " cannot be created");
            }
        }

        // means that directory for programs created succesfully or it already exists
View Full Code Here

Examples of org.apache.stanbol.contenthub.servicesapi.ldpath.LDPathException

    @Override
    public void submitProgram(String programName, String ldPathProgram) throws LDPathException {
        if (programName == null || programName.isEmpty()) {
            String msg = "Program name cannot be null or empty";
            logger.error(msg);
            throw new LDPathException(msg);
        }

        if (ldPathProgram == null || ldPathProgram.isEmpty()) {
            String msg = "LDPath program cannot be null or empty";
            logger.error(msg);
            throw new LDPathException(msg);
        }

        // Checks whether there is already a program with the same name
        if (nameProgramMap.containsKey(programName)) {
            String msg = String.format("There is already an LDProgram with name : %s", programName);
            logger.error(msg);
            throw new LDPathException(msg);
        }

        try {
            SolrCoreManager.getInstance(bundle.getBundleContext(), managedSolrServer).createSolrCore(
                programName, ldPathUtils.createSchemaArchive(programName, ldPathProgram));
        } catch (LDPathException e) {
            logger.error("Solr Core Service could NOT initialize Solr core with name : {}", programName);
            throw e;
        } catch (StoreException e) {
            throw new LDPathException(e.getMessage(), e);
        }

        String programFilePath = managedProgramsDir.getAbsolutePath() + File.separator + programName;
        try {
            FileUtils.writeStringToFile(new File(programFilePath), ldPathProgram);
        } catch (IOException e) {
            String msg = "Cannot write the LDPath program to file. The state is inconsistent now. "
                         + "The Solr core is created, but corresponding LDPath program does not exist.";
            logger.error(msg, e);
            throw new LDPathException(msg, e);
        }
        nameProgramMap.put(programName, ldPathProgram);

        logger.info("SolrCore for the {} created succesfully and corresponding LDPath program saved ",
            programName);
View Full Code Here

Examples of org.apache.stanbol.contenthub.servicesapi.ldpath.LDPathException

        try {
            ldPathProgram = IOUtils.toString(ldPathProgramReader);
        } catch (IOException e) {
            String msg = "Cannot convert to String from Reader (ldPathProgramReader) in submitProgram";
            logger.error(msg, e);
            throw new LDPathException(msg, e);
        }
        submitProgram(programName, ldPathProgram);
    }
View Full Code Here

Examples of org.apache.stanbol.contenthub.servicesapi.ldpath.LDPathException

                    program.getBytes(Constants.DEFAULT_ENCODING)), Constants.DEFAULT_ENCODING);
        } catch (UnsupportedEncodingException e) {
            String msg = String.format("Encoding %s should be supported by the system",
                Constants.DEFAULT_ENCODING);
            logger.error(msg, e);
            throw new LDPathException(msg, e);
        }
    }
View Full Code Here

Examples of org.apache.stanbol.contenthub.servicesapi.ldpath.LDPathException

    private Program<Object> getLDPathProgram(String ldPathProgram) throws LDPathException {
        if (ldPathProgram == null || ldPathProgram.isEmpty()) {
            String msg = "LDPath Program cannot be null.";
            logger.error(msg);
            throw new LDPathException(msg);
        }
        RDFBackend<Object> rdfBackend = new SiteManagerBackend(referencedSiteManager);
        RdfPathParser<Object> LDparser = new RdfPathParser<Object>(rdfBackend, constructReader(ldPathProgram));
        Program<Object> program = null;
        try {
            program = LDparser.parseProgram();
        } catch (ParseException e) {
            String msg = "Cannot parse LDPath Program";
            logger.error(msg, e);
            throw new LDPathException(msg, e);
        }
        return program;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.