Package org.fao.geonet.kernel

Examples of org.fao.geonet.kernel.SchemaManager


  public Element exec(Element params, ServiceContext context) throws Exception
  {
    GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);

    SchemaManager schemaMan = gc.getBean(SchemaManager.class);

    Element schemas = new Element("schemas");

    for(String schema : schemaMan.getSchemas()) {
      try {
        Map<String, XmlFile> schemaInfo = schemaMan.getSchemaInfo(schema);

        for (Map.Entry<String, XmlFile> entry : schemaInfo.entrySet()) {
          XmlFile xf = entry.getValue();
          String fname = entry.getKey();
          Element response = xf.exec(new Element("junk"), context);
View Full Code Here


            throw new AssertionError(functionName + " in " + name + " does not compile due to: '"+e.getMessage()+"'\n\n"+function.getText());
        }
    }

    private void addSchematron(String schemaName) {
        final SchemaManager schemaManager = _applicationContext.getBean(SchemaManager.class);
        final SchematronRepository repo = _applicationContext.getBean(SchematronRepository.class);
        Schematron schematron = new Schematron();
        schematron.setSchemaName(schemaName);
        schematron.setFile(schemaManager.getSchemaDir(schemaName) + File.separator + "schematron" + File.separator
                           + "schematron-rules-geonetwork.sch");
        repo.save(schematron);
    }
View Full Code Here

  public Element exec(Element params, ServiceContext context) throws Exception
  {
    GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);

    SchemaManager schemaMan = gc.getBean(SchemaManager.class);

    Element schemas = new Element("schemalist");

    for (String schema : schemaMan.getSchemas()) {
      Element elem = new Element("name").setText(schema);
      elem.setAttribute("plugin","true"); // all schemas are plugins
      elem.setAttribute("schemaConvertDirectory",schemaMan.getSchemaDir(schema)+"convert"+FS);
      elem.setAttribute("namespaces",schemaMan.getNamespaceString(schema));
      // is it editable?
      if (schemaMan.getSchema(schema).canEdit()) {
        elem.setAttribute("edit","true");
      } else {
        elem.setAttribute("edit","false");
      }
      // get the conversion information and add it too
      List<Element> convElems = schemaMan.getConversionElements(schema);
      if (convElems.size() > 0) {
        Element conv = new Element("conversions");
        conv.addContent(convElems);
        elem.addContent(conv);
      }
View Full Code Here

    Element result = new Element(Jeeves.Elem.RESPONSE);

    GeonetContext gc = (GeonetContext) context
        .getHandlerContext(Geonet.CONTEXT_NAME);
    SchemaManager schemaMan = gc.getBean(SchemaManager.class);

    String schemas[] = schemaList.split(",");

        int count = 0;
    for (String schemaName : schemas) {
      Log.info(Geonet.DATA_MANAGER, "Loading sample data for schema "
          + schemaName);
      String schemaDir = schemaMan.getSchemaSampleDataDir(schemaName);
      if (schemaDir == null) {
        Log.error(Geonet.DATA_MANAGER, "Skipping - No sample data?");
                result.addContent(new Element(schemaName).setText("0"));
        continue;
      }
View Full Code Here

            subTemplateTypes.addContent(new Element("type").setText(metadata.getDataInfo().getRoot()));
            subTemplateTypes.addContent(new Element("schemaId").setText(metadata.getDataInfo().getSchemaId()));
        }

        GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
        SchemaManager scm = gc.getBean(SchemaManager.class);

        for (Object e : subTemplateTypes.getChildren()) {
            if (e instanceof Element) {
              Element record = ((Element)e);
              try {
View Full Code Here

    // function builds a OAI records from a metadata record, according to the arguments select and selectVal
    public static Record buildRecordStat(ServiceContext context, Specification<Metadata> spec/*String select, Object selectVal*/,
                                         String prefix) throws Exception {
        GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
        SchemaManager sm = gc.getBean(SchemaManager.class);

        Metadata metadata = context.getBean(MetadataRepository.class).findOne(spec);
        if (metadata == null)
            throw new IdDoesNotExistException(spec.toString());

        String uuid = metadata.getUuid();
        final MetadataDataInfo dataInfo = metadata.getDataInfo();
        String schema = dataInfo.getSchemaId();
        String changeDate = dataInfo.getChangeDate().getDateAndTime();
        String data = metadata.getData();

        Element md = Xml.loadString(data, false);

        //--- try to disseminate format

        if (prefix.equals(schema)) {
            Attribute schemaLocAtt = sm.getSchemaLocation(schema, context);
            if (schemaLocAtt != null) {
                if (md.getAttribute(schemaLocAtt.getName(), schemaLocAtt.getNamespace()) == null) {
                    md.setAttribute(schemaLocAtt);
                    // make sure namespace declaration for schemalocation is present -
                    // remove it first (does nothing if not there) then add it
                    md.removeNamespaceDeclaration(schemaLocAtt.getNamespace());
                    md.addNamespaceDeclaration(schemaLocAtt.getNamespace());
                }
            }
        } else {
            String schemaDir = sm.getSchemaDir(schema);
            if (Lib.existsConverter(schemaDir, prefix)) {
                final String siteURL = context.getBean(SettingManager.class).getSiteURL(context);
                Element env = Lib.prepareTransformEnv(uuid, changeDate, context.getBaseUrl(), siteURL, gc.getBean(SettingManager.class)
                        .getSiteName());
                md = Lib.transform(schemaDir, env, md, prefix + ".xsl");
View Full Code Here

  @SuppressWarnings("unchecked")
  private Header buildHeader(ServiceContext context, int id, String prefix) throws Exception
  {
    GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
    SchemaManager   sm = gc.getBean(SchemaManager.class);

        final Metadata metadata = gc.getBean(MetadataRepository.class).findOne(id);

    //--- maybe the metadata has been removed

    if (metadata == null) {
      return null;
        }

    String uuid       = metadata.getUuid();
    String schema     = metadata.getDataInfo().getSchemaId();
    ISODate changeDate = metadata.getDataInfo().getChangeDate();

    //--- try to disseminate format if not by schema then by conversion

    if (!prefix.equals(schema)) {
      if (!Lib.existsConverter(sm.getSchemaDir(schema), prefix)) {
        return null;
      }
    }

    //--- build header and set some infos
View Full Code Here

  {
    ListMetadataFormatsRequest  req = (ListMetadataFormatsRequest) request;
    ListMetadataFormatsResponse res = new ListMetadataFormatsResponse();

    GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
    SchemaManager   sm = gc.getBean(SchemaManager.class);

    String uuid = req.getIdentifier();
    if (uuid != null)
    {
            String schema = context.getBean(MetadataRepository.class).findOneByUuid(uuid).getDataInfo().getSchemaId();
      res.addFormat(getSchemaInfo(context, sm, schema));
    }
    else
    {
      for (String schema : sm.getSchemas())
        res.addFormat(getSchemaInfo(context, sm, schema));
    }

    for (MetadataFormat mdf : getConvertFormats(context)) {
      res.addFormat(mdf);
View Full Code Here

                                    Set<Integer> metadata) throws Exception {

        GeonetContext gc = (GeonetContext) context
                .getHandlerContext(Geonet.CONTEXT_NAME);
        DataManager dataMan = gc.getBean(DataManager.class);
        SchemaManager schemaMan = gc.getBean(SchemaManager.class);
        AccessManager accessMan = gc.getBean(AccessManager.class);

        report.incrementProcessedRecords();

        // When a record is deleted the UUID is in the selection manager
        // and when retrieving id, return null
        if (id == null) {
            report.incrementNullRecords();
            return null;
        }

        int iId = Integer.valueOf(id);

        Metadata metadataEntity =  context.getBean(MetadataRepository.class).findOne(iId);
        MetadataDataInfo info = metadataEntity.getDataInfo();

        // Get metadata title from the index
        String metadataTitle = LuceneSearcher.getMetadataFromIndexById(context.getLanguage(), id, "title");
        if (StringUtils.isEmpty(metadataTitle)) metadataTitle = metadataEntity.getUuid();

        if (info == null) {
            MassiveReplaceReportEntry notFoundEntry =
                    new MassiveReplaceReportEntry(id, "", null);
            report.addNotFound(notFoundEntry);

        } else if (!accessMan.isOwner(context, id)) {
            MassiveReplaceReportEntry notOwnerEntry =
                    new MassiveReplaceReportEntry(metadataEntity.getUuid(), metadataTitle, null);
            report.addNotEditable(notOwnerEntry);
        } else {

            // -----------------------------------------------------------------------
            // --- check processing exist for current schema
            String schema = info.getSchemaId();
            String filePath = schemaMan.getSchemaDir(schema) + "/process/" + process + ".xsl";
            File xslProcessing = new File(filePath);
            if (!xslProcessing.exists()) {
                context.info("  Processing instruction not found for " + schema
                        + " schema.");

                MassiveReplaceReportEntry notOwnerEntry =
                        new MassiveReplaceReportEntry(metadataEntity.getUuid(), metadataTitle, null);
                report.addNoProcessFound(notOwnerEntry);

                return null;
            }
            // --- Process metadata
            Element processedMetadata = null;

            try {
                Element md = dataMan.getMetadataNoInfo(context, id);

                // -- here we send parameters set by user from
                // URL if needed.
                List<Element> children = params.getChildren();
                Map<String, Object> xslParameter = new HashMap<String, Object>();
                for (Element param : children) {
                    if (param.getChildren().size() > 0) {
                        xslParameter.put(param.getName(), param);
                    } else {
                        xslParameter.put(param.getName(), param.getTextTrim());

                    }
                }

                processedMetadata = Xml.transformWithXmlParam(md, filePath, paramNameXml, paramXml);

                // Get changes
                String filePath2 = schemaMan.getSchemaDir(schema) + "/process/massive-content-update-extract-changes.xsl";
                List<Element> changesEl = Xml.transform(processedMetadata, filePath2).getChildren("change");

                boolean hasChanges = (changesEl.size() > 0);


                MassiveReplaceReportEntry mdEntry = new MassiveReplaceReportEntry(metadataEntity.getUuid(),
                        metadataTitle,
                        changesEl);

                if (hasChanges) {
                    report.addChanged(mdEntry);
                } else {
                    report.addNotChanged(mdEntry);
                }

                // --- save metadata and return status
                if ((changesEl.size() > 0) && (!params.getChildText("test").equalsIgnoreCase("true"))) {
                    // Clean geonet:changes elements
                    String filePath3 = schemaMan.getSchemaDir(schema) + "/process/massive-content-update-clean-changes.xsl";
                    processedMetadata = Xml.transform(processedMetadata, filePath3);

                    dataMan.updateMetadata(context, id, processedMetadata,
                            false, true, true,
                            context.getLanguage(),
View Full Code Here

  //--------------------------------------------------------------------------

  private Element getSchemaFragmentStylesheets(Element el, ServiceContext context, String xslFragmentDir, String schemaFilter) throws Exception {

    GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
    SchemaManager schemaMan = gc.getBean(SchemaManager.class);

    Element elRoot = new Element("stylesheets");

    for (String schema : schemaMan.getSchemas()) {
      if (!schemaFilter.equals("") && !schema.equals(schemaFilter)) continue;
      File xslPath = new File(schemaMan.getSchemaDir(schema)+xslFragmentDir)
      if (!xslPath.exists()) continue;

      @SuppressWarnings("unchecked")
            List<Element> elSheets = getStylesheets(el, context, xslPath).getChildren();
      for (Element elSheet : elSheets) {
View Full Code Here

TOP

Related Classes of org.fao.geonet.kernel.SchemaManager

Copyright © 2018 www.massapicom. 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.