Package org.fao.geonet

Examples of org.fao.geonet.GeonetContext


   * selection manager.
   *
   */
  public Element exec(Element params, ServiceContext context) throws Exception
  {
    GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
   
    SearchManager searchMan = gc.getBean(SearchManager.class);

    String restoreLastSearch = _config.getValue("restoreLastSearch","no");

    // store or possibly close old searcher
    UserSession  session     = context.getUserSession();
View Full Code Here


        UserSession session = context.getUserSession();
        KeywordsSearcher searcher = (KeywordsSearcher) session
          .getProperty(Geonet.Session.SEARCH_KEYWORDS_RESULT);
        kb = searcher.getKeywordFromResultsById(id);
      }else{
        GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
        ThesaurusManager thesaurusMan = gc.getBean(ThesaurusManager.class);
        KeywordsSearcher searcher = new KeywordsSearcher(context, thesaurusMan);
       
        kb = searcher.searchById(uri, ref, lang);
       
      }
      // Add info needed by thesaurus.edit
      elResp.addContent(new Element("prefLab").setText(kb.getDefaultValue()));
      elResp.addContent(new Element("definition").setText(kb.getDefaultDefinition()));

      elResp.addContent(new Element("relCode").setText(kb.getRelativeCode()));
      elResp.addContent(new Element("nsCode").setText(kb.getNameSpaceCode()));
      if (kb.getCoordEast() != null) {
                elResp.addContent(new Element("east").setText(kb.getCoordEast()));
            }
      if (kb.getCoordWest() != null) {
                elResp.addContent(new Element("west").setText(kb.getCoordWest()));
            }
      if (kb.getCoordSouth() != null) {
                elResp.addContent(new Element("south").setText(kb.getCoordSouth()));
            }
      if (kb.getCoordNorth() != null) {
                elResp.addContent(new Element("north").setText(kb.getCoordNorth()));
            }
     

      modeType   = "edit";
      uri     = kb.getRelativeCode();
    } else {
      elResp.addContent(new Element("nsCode").setText("#"));
    }
   
   
    // Only if consult (ie. external thesaurus) search for related concept
    if (mode.equals("consult")){
      ArrayList<KeywordRelation> reqType = new ArrayList<KeywordRelation>();
      reqType.add(KeywordRelation.BROADER);
      reqType.add(KeywordRelation.NARROWER);
      reqType.add(KeywordRelation.RELATED);
     
      GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
      ThesaurusManager thesaurusMan = gc.getBean(ThesaurusManager.class);
      KeywordsSearcher searcherBNR = new KeywordsSearcher(context, thesaurusMan);
     
      for (int i = 0; i <= reqType.size() - 1; i++) {
        searcherBNR.searchForRelated(uri, ref, reqType.get(i), lang);
     
View Full Code Here

   * @throws EmailException
   */
  public static void process(ServiceContext context, Element element,
      @SuppressWarnings("rawtypes") AbstractHarvester abstractHarvester)
      throws EmailException {
    GeonetContext gc = (GeonetContext) context
        .getHandlerContext(Geonet.CONTEXT_NAME);
    SettingManager settings = gc.getBean(SettingManager.class);
    notifyByMail(settings, element, abstractHarvester);
  }
View Full Code Here

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

  public Element exec(Element params, ServiceContext context) throws Exception
  {
    GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
    boolean asTree = Util.getParam(params, "asTree", "true").equals("true");

        Element system  = gc.getBean(SettingManager.class).getAllAsXML(asTree);
    return system;
  }
View Full Code Here

  public FragmentHarvester(Logger log, ServiceContext context, FragmentParams params) {
    this.log    = log;
    this.context= context;
    this.params = params;

    GeonetContext gc = (GeonetContext) context.getHandlerContext (Geonet.CONTEXT_NAME);
    dataMan = gc.getBean(DataManager.class);

    SettingInfo si = context.getBean(SettingInfo.class);
    String siteUrl = si.getSiteUrl() + context.getBaseUrl();
    metadataGetService = siteUrl + "/srv/en/xml.metadata.get";
View Full Code Here

        if ("".equals(file)) {
            throw new Exception("Logo name is not defined.");
        }

        GeonetContext gc = (GeonetContext) context
                .getHandlerContext(Geonet.CONTEXT_NAME);
        SettingManager settingMan = gc.getBean(SettingManager.class);
        String nodeUuid = settingMan.getSiteId();

        try {
          String logoFilePath = harvestingLogoDirectory + File.separator + file;
          File logoFile = new File(logoFilePath);
View Full Code Here

    }

    @Override
    public Element exec(Element params, ServiceContext context)
            throws Exception {
        GeonetContext gc = (GeonetContext) context
                .getHandlerContext(Geonet.CONTEXT_NAME);
    SettingManager settings = gc.getBean(SettingManager.class);

        String sendTo = "";
       
        for (Object o : params.getChildren()) {
            Element param = ((Element) o);
View Full Code Here

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

  public Element serviceSpecificExec(Element params, ServiceContext context) throws Exception
  {
    GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
    DataManager   dataMan   = gc.getBean(DataManager.class);
    UserSession   session   = context.getUserSession();

    Set<Integer> metadata = new HashSet<Integer>();
    Set<Integer> notFound = new HashSet<Integer>();
    Set<Integer> notOwner = new HashSet<Integer>();
View Full Code Here

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

  private void processRecord(ServiceContext context, String uuid, String category, String xpath, String getTit, String xpathTit, boolean doChanges, Set<Integer> metadata, Set<Integer> notFound, Set<Integer> notOwner, Set<Integer> subtemplates, Element response) throws Exception {

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

    if (context.isDebugEnabled())
      context.debug("Extracting subtemplates from metadata with uuid:"+ uuid);

        final MetadataRepository metadataRepository = context.getBean(MetadataRepository.class);
View Full Code Here

  }

  @SuppressWarnings("unchecked")
    private void extractSubtemplates(ServiceContext context, DataManager dataMan, Metadata metadataEntity, String category, String xpath, String getTit, String xpathTit, boolean doChanges, Set<Integer> metadata, Set<Integer> subtemplates, Element response) throws Exception {

    GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);

    // get metadata
    Element md = dataMan.getMetadataNoInfo(context, "" + metadataEntity.getId());
        MetadataDataInfo mdInfo = metadataEntity.getDataInfo();

    // Build a list of all Namespaces in the metadata document
    List<Namespace> metadataNamespaces = namespaceList.get(mdInfo.getSchemaId());
    if (metadataNamespaces == null) {
      metadataNamespaces = new ArrayList<Namespace>();
      Namespace ns = md.getNamespace();
      if (ns != null) {
        metadataNamespaces.add(ns);
        metadataNamespaces.addAll(md.getAdditionalNamespaces());
        namespaceList.put(mdInfo.getSchemaId(), metadataNamespaces);
      }
    }

    new Document(md);
    // select all nodes that come back from the xpath selectNodes
    List<?> nodes = Xml.selectNodes(md, xpath, metadataNamespaces);
    if (context.isDebugEnabled() || !doChanges) {
      context.debug("xpath \n"+xpath+"\n returned "+nodes.size()+" results");
      if (!doChanges) {
        response.addContent(new Element("xpath").setText(xpath));
        response.addContent(new Element("xpathReturned").setText(nodes.size()+" results"));
      }
    }


    // for each node
    for (Iterator<?> iter = nodes.iterator(); iter.hasNext();) {
      Object o = iter.next();
      if (o instanceof Element) {
        Element elem = (Element)o;
        if (context.isDebugEnabled() || !doChanges) {
          context.debug("Test: Subtemplate with \n"+Xml.getString(elem));
          if (!doChanges) {
            response.addContent(new Element("subtemplate").setText(Xml.getString(elem)));
          }
        }

        // extract title from node
        String title = null;
        if (getTit.length() > 0) { // use xslt path in getTit
          Element xmlTitle = Xml.transform((Element)elem.clone(), getTit);
          if (context.isDebugEnabled() || !doChanges) {
            context.debug("Test: Title \n"+Xml.getString(xmlTitle));
          }
          title = xmlTitle.getText();
        } else { // use xpathTit
          List<?> titNodes = Xml.selectNodes(elem, xpathTit, metadataNamespaces);
          StringBuilder sb = new StringBuilder();
          for (Iterator<?> iterTit = titNodes.iterator(); iterTit.hasNext();) {
            Object oTit = iterTit.next();
            if (oTit instanceof Element) { // getText
              Element eTit = (Element)oTit;
              sb.append(eTit.getTextTrim());
            } else if (oTit instanceof Comment) { // not sure about this one!
              Comment cTit = (Comment)oTit;
              sb.append(cTit.getText());
            } else if (oTit instanceof Attribute) {
              Attribute aTit = (Attribute)oTit;
              sb.append(aTit.getValue());
            } else if (oTit instanceof Text) {
              Text tTit = (Text)oTit;
              sb.append(tTit.getTextTrim());
            }
            sb.append(" ");
          }
          title = sb.toString().trim();
        }

        if (!doChanges) {
          response.addContent(new Element("title").setText(title));
        }

 
        String uuid = elem.getAttributeValue("uuid");
        if (uuid == null || uuid.length() == 0) {
          // calc uuid based on sha1sum of content - this is the way to
          // generate this safely
          uuid = Sha1Encoder.encodeString(elem.getValue());
        }
 
        if (doChanges) { // insert subtemplate if it isn't already present
          if (dataMan.getMetadataId(uuid) != null) {
            context.debug("Test: Subtemplate with uuid "+uuid+" already exists");
          } else {
            //if (context.isDebug()) context.info("Test: Add subtemplate uuid "+uuid);

            // add node as a subtemplate
            String docType = null, createDate = null, changeDate = null;
            String group = "1";
            int user = context.getUserSession().getUserIdAsInt();
            boolean ufo = false, indexImmediate = false;

                        String sId = dataMan.insertMetadata(context, mdInfo.getSchemaId(), (Element) elem.clone(), uuid, user, group,
                                gc.getBean(SettingManager.class).getSiteId(), "s", docType, category, createDate, changeDate, ufo, indexImmediate);
            subtemplates.add(Integer.valueOf(sId));
          }
        }

        // replace node in record with a new node and xlink to the subtemplate
View Full Code Here

TOP

Related Classes of org.fao.geonet.GeonetContext

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.