Package org.fao.geonet.domain

Examples of org.fao.geonet.domain.MetadataDataInfo


    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));
          }
        }
View Full Code Here


        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
View Full Code Here

        }

        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.");
View Full Code Here

     */
    public void setTemplateExt(final int id, final MetadataType metadataType) throws Exception {
        _metadataRepository.update(id, new Updater<Metadata>() {
            @Override
            public void apply(@Nonnull Metadata metadata) {
                final MetadataDataInfo dataInfo = metadata.getDataInfo();
                dataInfo.setType(metadataType);
            }
        });
    }
View Full Code Here

            // Update the popularity in database
            Integer iId = Integer.valueOf(id);
            _metadataRepository.update(iId, new Updater<Metadata>() {
                @Override
                public void apply(@Nonnull Metadata entity) {
                    final MetadataDataInfo dataInfo = entity.getDataInfo();
                    int popularity = dataInfo.getPopularity();
                    dataInfo.setPopularity(popularity + 1);
                }
            });

            // And register the metadata to be indexed in the near future
            final IndexingList list = srvContext.getBean(IndexingList.class);
View Full Code Here

     * @return
     * @throws Exception
     */
    private Element buildInfoElem(ServiceContext context, String id, String version) throws Exception {
        Metadata metadata = _metadataRepository.findOne(id);
        final MetadataDataInfo dataInfo = metadata.getDataInfo();
        String schema = dataInfo.getSchemaId();
        String createDate = dataInfo.getCreateDate().getDateAndTime();
        String changeDate = dataInfo.getChangeDate().getDateAndTime();
        String source = metadata.getSourceInfo().getSourceId();
        String isTemplate = dataInfo.getType().codeString;
        String title = dataInfo.getTitle();
        String uuid = metadata.getUuid();
        String isHarvested = "" + Constants.toYN_EnabledChar(metadata.getHarvestInfo().isHarvested());
        String harvestUuid = metadata.getHarvestInfo().getUuid();
        String popularity = "" + dataInfo.getPopularity();
        String rating = "" + dataInfo.getRating();
        String owner = "" + metadata.getSourceInfo().getOwner();
        String displayOrder = "" + dataInfo.getDisplayOrder();

        Element info = new Element(Edit.RootChild.INFO, Edit.NAMESPACE);

        addElement(info, Edit.Info.Elem.ID, id);
        addElement(info, Edit.Info.Elem.SCHEMA, schema);
View Full Code Here

TOP

Related Classes of org.fao.geonet.domain.MetadataDataInfo

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.