Package org.fao.geonet.kernel

Examples of org.fao.geonet.kernel.SchemaManager


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

  private Element getSchemas(Element el, ServiceContext context, String xslPathStr) throws Exception {

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

    Element elRoot = new Element("schemas");

    for (String schema : schemaMan.getSchemas()) {
      File xslPath = new File(schemaMan.getSchemaDir(schema)+xslPathStr)
      if (xslPath.exists()) {
        Element res = new Element(Jeeves.Elem.RECORD);
       
        res.addContent(new Element(Geonet.Elem.ID.setText(schema));
        res.addContent(new Element(Geonet.Elem.NAME).setText(schema));
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 result = search(params, context).setName(Jeeves.Elem.RESPONSE);

    @SuppressWarnings("unchecked")
        List<Element> list = result.getChildren();

    Element response = new Element("dummy");

        // heikki: geonovum: first build the list of response records
        List<Element> responseRecords = new ArrayList<Element>();

        for (Element elem : list) {
            Element info = elem.getChild(Edit.RootChild.INFO, Edit.NAMESPACE);

            if (!elem.getName().equals("metadata")) {
                continue;
            }

            String template     = elem.getChildText("isTemplate");
            String displayOrder = elem.getChildText("displayOrder");
            String schema = info.getChildText("schema");
            String id     = info.getChildText(Edit.Info.Elem.ID);

            if (template.equals("y") && schemaMan.existsSchema(schema)) {
                // heikki, GeoNovum: added displayOrder
                responseRecords.add(buildRecord(id, elem.getChildText("title"), schema, displayOrder));
            }
        }
        // heikki, Geonovum: then process them to ensure displayOrder is not empty and is unique
View Full Code Here

    public void init(String appPath, ServiceConfig params) throws Exception {
    }

    @Override
    public Element exec(Element params, ServiceContext context) throws Exception {
        SchemaManager schemaManager = context.getApplicationContext().getBean(SchemaManager.class);
        SchematronCriteriaGroupRepository criteriaGroupRepo = context.getApplicationContext().getBean(SchematronCriteriaGroupRepository.class);
        final XmlCacheManager cacheManager = context.getBean(XmlCacheManager.class);

        Element schematrons = schematronService.exec(params, context);
        Element results = new Element(Jeeves.Elem.RESPONSE);
        Element schemas = new Element("schemas");
        results.addContent(schemas);
        Element requirements = new Element("requirements");
        for (SchematronRequirement requirement : SchematronRequirement.values()) {
            requirements.addContent(new Element("requirement").setText(requirement.name()));
        }
        results.addContent(requirements);
        @SuppressWarnings("unchecked")
        List<Element> schematronElements = Lists.newArrayList(schematrons.getChildren());

        for (Element element : schematronElements) {
            String schemaname = element.getChildText("schemaname");
            Element schemaEl = schemas.getChild(schemaname);
            if (schemaEl == null) {
                schemaEl = new Element(schemaname);

                schemaEl.addContent(new Element("name").setText(schemaname));
                addCriteriaTypeDefinition(context, schemaManager, schemaEl, schemaname);
                schemas.addContent(schemaEl);
            }

            element.setName("schematron");
            addTitleToSchematronElement(context, cacheManager, element, schemaManager.getSchemaDir(schemaname));
            schemaEl.addContent(element.detach());

            addSchematronGroupCount(criteriaGroupRepo, element, element.getChildText("id"));
        }
View Full Code Here

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

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

        Element response = new Element("response");

        for (Object o : params.getChildren()) {
            Element elem = (Element) o;
View Full Code Here

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

  public Element exec(Element params, ServiceContext context) throws Exception {

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

    String schema = Util.getParam(params, Params.SCHEMA);
    String urlStr, uuid, fname;
    uuid = "";
    URL url = null;

    // -- try the file name argument then the url then the uuid of a metadata
    // -- record to which a schema is attached
    fname = Util.getParam(params, Params.FNAME, "");
    if ("".equals(fname)) {
      urlStr = Util.getParam(params, Params.URL, "");
      if ("".equals(urlStr)) {
        uuid = Util.getParam(params, Params.UUID, "");
        if ("".equals(uuid)) {
          throw new IllegalArgumentException("One of fname, url or uuid must be supplied");
        }
      } else {
        try {
          url = new URL(urlStr);
        } catch (MalformedURLException mu) {
           throw new OperationAbortedEx("URL "+urlStr+" is malformed: "+mu.getMessage());
        }
      }
    }

    // -- test if schema already exists, if so then chuck a fit and exit
    if (scm.existsSchema(schema)) {
     throw new OperationAbortedEx("Schema already exists");
    }

    SchemaUtils su = new SchemaUtils();
    return su.addSchema(context, schema, fname, url, uuid, scm);
View Full Code Here

    Element result = new Element(Jeeves.Elem.RESPONSE);
    GeonetContext gc = (GeonetContext) context
        .getHandlerContext(Geonet.CONTEXT_NAME);

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

        String siteId = gc.getBean(SettingManager.class).getSiteId();
    int owner = context.getUserSession().getUserIdAsInt();

    Log.info(Geonet.DATA_MANAGER, "Loading templates for schemas "
        + schemaList);
    String schemas[] = schemaList.split(",");

    for (String schemaName : schemas) {

      Element schema = new Element(schemaName);

      String schemaDir = schemaMan.getSchemaTemplatesDir(schemaName);
      if (schemaDir == null) {
        Log.error(Geonet.DATA_MANAGER, "Skipping - No templates?");
        continue;
      }
View Full Code Here

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

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

    String id = Utils.getIdentifierFromParameters(params, context);
    if (id == null) throw new MetadataNotFoundEx("Metadata not found.");

    Element elMd = new Show().exec(params, context);
    if (elMd == null) throw new MetadataNotFoundEx(id);

    //--- get XSLT converter name from params
    String styleSheet = Util.getParam(params, Params.STYLESHEET);

    //--- get metadata info and create an env that works with oai translators
        final Metadata metadata = context.getBean(MetadataRepository.class).findOne(id);
    String schemaDir = sm.getSchemaDir(metadata.getDataInfo().getSchemaId());
        final String baseUrl = context.getBaseUrl();
        final ISODate changeDate = metadata.getDataInfo().getChangeDate();
        final String uuid = metadata.getUuid();
        final String siteURL = context.getBean(SettingManager.class).getSiteURL(context);
        final String siteName = gc.getBean(SettingManager.class).getSiteName();
View Full Code Here

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

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

    String schema = Util.getParam(params, Params.SCHEMA);

    // see if the schema to be deleted actually exists
    Element response = new Element("response");
    if (!scm.existsSchema(schema)) {
      response.setAttribute("status", "error");
      response.setAttribute("message", "Schema does not exist");
      return response;
    }

    // fast search to see if any records are present that use this schema
    ServiceConfig config = new ServiceConfig();

    SearchManager searchMan = gc.getBean(SearchManager.class);
    Element searchParams = new Element("parameters")
    searchParams.addContent(new Element("_schema").setText(schema));

     MetaSearcher  searcher  = searchMan.newSearcher(SearchManager.LUCENE, Geonet.File.SEARCH_LUCENE);
    try {
       searcher.search(context, searchParams, config);
      int results = searcher.getSize();
      if (results == 0) { // check for templates
        searchParams.addContent(new Element("_isTemplate").setText("y"));
         searcher.search(context, searchParams, config);
        results = searcher.getSize();
      }
      if (results > 0) {
        String errStr = "Cannot remove schema "+schema+" because there are records that belong to this schema in the catalog";
        context.error(errStr);
        response.setAttribute("status", "error");
        response.setAttribute("message", errStr);
        return response;
      }
    } catch (Exception e) {
      e.printStackTrace();
      String errStr = "Cannot remove schema "+schema+" because the search for records that belong to this schema FAILED ("+e.getMessage()+")";
      context.error(errStr);
      response.setAttribute("status", "error");
      response.setAttribute("message", errStr);
      return response;
    } finally {
       searcher.close();
    }

    // check for any schemas that may be dependent on the schema to be deleted
    List<String> dependsOnMe = scm.getSchemasThatDependOnMe(schema);
    if (dependsOnMe.size() > 0) {
      String errStr = "Cannot remove schema "+schema+" because the following schemas list it as a dependency: "+dependsOnMe;

      context.error(errStr);
      response.setAttribute("status", "error");
      response.setAttribute("message", errStr);
      return response;
    }

    // finally, try to delete the schema
    try {
      scm.deletePluginSchema(schema);
      response.setAttribute("status", "ok");
      response.setAttribute("message", "Schema "+schema+" deleted");
    } catch (Exception e) {
      e.printStackTrace();
      response.setAttribute("status", "error");
View Full Code Here

    private synchronized List<SchemaLocalization> getLabels(ServiceContext context, String lang) throws IOException, JDOMException {
        GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
        List<SchemaLocalization> localization = labels.get(lang);
        if(localization == null) {
            SchemaManager schemamanager = gc.getBean(SchemaManager.class);
            Set<String> schemas = schemamanager.getSchemas();
            localization = new ArrayList<SchemaLocalization>(schemas.size());
            for (String schema : schemas) {
                String schemaLocDir = schemamanager.getSchemaDir(schema)+File.separator+"loc"+File.separator+lang+File.separator;
                localization.add(new SchemaLocalization(schema, schemaLocDir));
                labels.put(lang, localization);
            }
        }
View Full Code Here

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

  public Element exec(Element params, ServiceContext context) throws Exception {

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

    String schema = Util.getParam(params, Params.SCHEMA);
    String urlStr, uuid, fname;
    uuid = "";
    URL url = null;

    // -- try the file name argument then the url then the uuid of a metadata
    // -- record to which a schema is attached
    fname = Util.getParam(params, Params.FNAME, "");
    if ("".equals(fname)) {
      urlStr = Util.getParam(params, Params.URL, "");
      if ("".equals(urlStr)) {
        uuid = Util.getParam(params, Params.UUID, "");
        if ("".equals(uuid)) {
          throw new IllegalArgumentException("One of fname, url or uuid must be supplied");
        }
      } else {
        try {
          url = new URL(urlStr);
        } catch (MalformedURLException mu) {
           throw new OperationAbortedEx("URL "+urlStr+" is malformed: "+mu.getMessage());
        }
      }
    }

    // -- test if schema to be updated exists, if not then chuck a fit and exit
    if (!scm.existsSchema(schema)) {
     throw new OperationAbortedEx("Schema doesn't exist");
    }

    SchemaUtils su = new SchemaUtils();
    return su.updateSchema(context, schema, fname, url, uuid, scm);
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.