Package org.fao.geonet.kernel

Examples of org.fao.geonet.kernel.DataManager


                                    ServiceContext context,
                                    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(),
                            new ISODate().toString(), true);
                }
View Full Code Here


     * @throws Exception
     */
  public Element serviceSpecificExec(Element params, ServiceContext context) throws Exception {
    GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);

    DataManager dataMan = gc.getBean(DataManager.class);
    String id = Utils.getIdentifierFromParameters(params, context);

    //--- check access
    int iLocalId = Integer.parseInt(id);
    if (!dataMan.existsMetadata(iLocalId))
      throw new IllegalArgumentException("Metadata not found --> " + id);

    //--- remove old operations
        context.getBean(MetadataRepository.class).update(iLocalId, new Updater<Metadata>() {
            @Override
            public void apply(@Nonnull Metadata entity) {
                entity.getCategories().clear();
            }
        });

    //--- set new ones
    @SuppressWarnings("unchecked")
        List<Element> list = params.getChildren();

    for (Element el : list) {
      String name = el.getName();

      if (name.startsWith("_"))
        dataMan.setCategory(context, id, name.substring(1));
    }

    //--- index metadata
        dataMan.indexMetadata(id, true);

        //--- return id for showing
    return new Element(Jeeves.Elem.RESPONSE).addContent(new Element(Geonet.Elem.ID).setText(id));
  }
View Full Code Here

        }

        Lib.resource.checkEditPrivilege(context, id);

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

        //--- check if the metadata has been modified from last time
        if (version != null && !dataMan.getVersion(id).equals(version)) {
            throw new ConcurrentUpdateEx(id);
        }


        File thumbnailFile = thumbnailMaker.generateThumbnail(
                jsonConfig,
                rotationAngle);

        //--- create destination directory
        String dataDir = Lib.resource.getDir(context, Params.Access.PUBLIC, id);

        IO.mkdirs(new File(dataDir), "Metadata data directory");

        File outFile = new File(dataDir, file);

        if (outFile.exists() && !outFile.delete()) {
            throw new Exception("Unable to overwrite existing file: " + outFile);
        }
        try {
            FileUtils.moveFile(thumbnailFile, outFile);
        } catch (Exception e) {
            IO.delete(thumbnailFile, false, context);
            throw new Exception(
                    "Unable to move uploaded thumbnail to destination: "
                            + outFile + ". Error: " + e.getMessage());
        }

        dataMan.setThumbnail(context, id, false, file, false);

        dataMan.indexMetadata(id, false);

        Element response = new Element("a");
        response.addContent(new Element("id").setText(id));
        response.addContent(new Element("version").setText(dataMan.getNewVersion(id)));
        return response;
    }
View Full Code Here

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

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

    DataManager dm = gc.getBean(DataManager.class);
    UserSession us = context.getUserSession();


    context.info("Get selected metadata");
    SelectionManager sm = SelectionManager.getManager(us);

    Element ret = new Element("response");
   
    String paramId = Util.getParam(params, "id", null) ;
    ArrayList<String> lst = new ArrayList<String>();
   
    // case #1 : #id parameter is undefined
    if (paramId == null) {
        synchronized(sm.getSelection("metadata")) {
            for (Iterator<String> iter = sm.getSelection("metadata").iterator(); iter.hasNext();) {
                String uuid = (String) iter.next();
                String id   = dm.getMetadataId(uuid);
                lst.add(id);
            }
        }
    } else { // case #2 : id parameter has been passed
        lst.add(paramId);
    }
       

    for (Iterator<String> iter = lst.iterator(); iter.hasNext();) {  
        String id = iter.next();

        Element curMd = dm.getMetadata(context, id, false, false, false);

        XPath xpath = XPath.newInstance("gmd:distributionInfo/gmd:MD_Distribution/gmd:transferOptions/gmd:MD_DigitalTransferOptions/gmd:onLine");

        List<Element> elems ;
View Full Code Here

      //--- data is not saved if someone else has changed the metadata
      update.exec(params, context);

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

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

    String id = Util.getParam(params, Params.ID);

    //-----------------------------------------------------------------------
    //--- get metadata

    Element result = dataMan.getThumbnails(context, id);

    if (result == null)
      throw new IllegalArgumentException("Metadata not found --> " + id);

    result.addContent(new Element("version").setText(dataMan.getNewVersion(id)));

    return result;
  }
View Full Code Here

    //-----------------------------------------------------------------------
    //--- extract thumbnail filename

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

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

    //--- check if the metadata has been modified from last time

    if (version != null && !dataMan.getVersion(id).equals(version))
      throw new ConcurrentUpdateEx(id);

    Element result = dataMan.getThumbnails(context, id);

    if (result == null)
      throw new OperationAbortedEx("Metadata not found", id);

    result = result.getChild(type);

    if (result == null)
      throw new OperationAbortedEx("Metadata has no thumbnail", id);

    String file = Lib.resource.getDir(context, Params.Access.PUBLIC, id) + getFileName(result.getText());

    //-----------------------------------------------------------------------
    //--- remove thumbnail

    dataMan.unsetThumbnail(context, id, type.equals("small"), true);
   
   
    File thumbnail = new File(file);
    if (thumbnail.exists()) {
      if (!thumbnail.delete()) {
        context.error("Error while deleting thumbnail: " + file);
      }
    } else {
            if(context.isDebugEnabled())
          context.debug("Thumbnail does not exist: " + file);
    }
   
    //-----------------------------------------------------------------------

    Element response = new Element("a");
    response.addContent(new Element("id").setText(id));
    response.addContent(new Element("version").setText(dataMan.getNewVersion(id)));

    return response;
  }
View Full Code Here

    if (!file.exists())
      throw new ResourceNotFoundEx(fname);

    GeonetContext  gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
    SettingManager sm = gc.getBean(SettingManager.class);
    DataManager    dm = gc.getBean(DataManager.class);

    //--- increase metadata popularity
    if (access.equals(Params.Access.PRIVATE))
      dm.increasePopularity(context, id);

    //--- send email notification

    if (doNotify)
    {
View Full Code Here

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

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

    context.info("Get selected metadata");
    SelectionManager sm = SelectionManager.getManager(us);

    Set<Integer> metadata = new HashSet<Integer>();
    Set<String> notFound = new HashSet<String>();
    Set<Integer> notOwner = new HashSet<Integer>();

    synchronized(sm.getSelection(SELECTION_METADATA)) {
    for (Iterator<String> iter = sm.getSelection(SELECTION_METADATA).iterator(); iter.hasNext();) {
      String uuid = iter.next();

      //--- check access

      Metadata info = context.getBean(MetadataRepository.class).findOneByUuid(uuid);
      if (info == null) {
        notFound.add(uuid);
      } else if (!accessMan.isOwner(context, String.valueOf(info.getId()))) {
        notOwner.add(info.getId());
      } else {

        //--- remove old operations
        boolean skip = false;

        //--- in case of owner, privileges for groups 0,1 and GUEST are
        //--- disabled and are not sent to the server. So we cannot remove them
        boolean isAdmin = Profile.Administrator == us.getProfile();
        boolean isReviewer= Profile.Reviewer == us.getProfile();

        if (us.getUserIdAsInt() == info.getSourceInfo().getOwner() && !isAdmin && !isReviewer) {
                    skip = true;
                }

        dm.deleteMetadataOper(context, "" + info.getId(), skip);

        //--- set new ones
        @SuppressWarnings("unchecked")
                List<Element> list = params.getChildren();

        for (Element el : list) {
          String name  = el.getName();

          if (name.startsWith("_")) {
            StringTokenizer st = new StringTokenizer(name, "_");

            String groupId = st.nextToken();
            String operId  = st.nextToken();

            dm.setOperation(context, "" + info.getId(), groupId, operId);
          }
        }
        metadata.add(info.getId());
      }
    }
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);

    String id = Utils.getIdentifierFromParameters(params, context);
    String ref    = Util.getParam(params, Params.REF);
    String access = Util.getParam(params, Params.ACCESS);

    Lib.resource.checkEditPrivilege(context, id);

    // get online resource name
        boolean forEditing = true, withValidationErrors = false, keepXlinkAttributes = false;
        Element metadata = dataMan.getMetadata(context, id, forEditing, withValidationErrors, keepXlinkAttributes);

    Element elem     = dataMan.getElementByRef(metadata, ref);

    if (elem == null)
      throw new ObjectNotFoundEx("element with ref='" + ref + "'");

    String fname = elem.getText();
View Full Code Here

        //-----------------------------------------------------------------------
        //--- environment vars

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

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

        //--- check if the metadata has been modified from last time

        if (version != null && !dataMan.getVersion(id).equals(version)) {
            throw new ConcurrentUpdateEx(id);
        }

        //-----------------------------------------------------------------------
        //--- create destination directory

        String dataDir = Lib.resource.getDir(context, Params.Access.PUBLIC, id);

        IO.mkdirs(new File(dataDir), "Metadata data directory");

        //-----------------------------------------------------------------------
        //--- create the small thumbnail, removing the old one

        if (createSmall) {
            String smallFile = getFileName(file, true);
            String inFile = context.getUploadDir() + file;
            String outFile = dataDir + smallFile;

            removeOldThumbnail(context, id, "small", false);
            createThumbnail(inFile, outFile, smallScalingFactor, smallScalingDir);
            dataMan.setThumbnail(context, id, true, smallFile, false);
        }

        //-----------------------------------------------------------------------
        //--- create the requested thumbnail, removing the old one

        removeOldThumbnail(context, id, type, false);

        if (scaling) {
            String newFile = getFileName(file, type.equals("small"));
            String inFile = context.getUploadDir() + file;
            String outFile = dataDir + newFile;

            createThumbnail(inFile, outFile, scalingFactor, scalingDir);

            if (!new File(inFile).delete())
                context.error("Error while deleting thumbnail : " + inFile);

            dataMan.setThumbnail(context, id, type.equals("small"), newFile, false);
        } else {
            //--- move uploaded file to destination directory

            File inFile = new File(context.getUploadDir(), file);
            File outFile = new File(dataDir, file);

            if (outFile.exists() && !outFile.delete()) {
                throw new Exception("Unable to overwrite existing file: " + outFile);
            }
            try {
                FileUtils.moveFile(inFile, outFile);
            } catch (Exception e) {
                IO.delete(inFile, false, context);
                throw new Exception(
                        "Unable to move uploaded thumbnail to destination: " + outFile + ". Error: " + e.getMessage());
            }

            dataMan.setThumbnail(context, id, type.equals("small"), file, false);
        }

        dataMan.indexMetadata(id, false);
        //-----------------------------------------------------------------------

        Element response = new Element("a");
        response.addContent(new Element("id").setText(id));
        response.addContent(new Element("version").setText(dataMan.getNewVersion(id)));

        return response;
    }
View Full Code Here

TOP

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

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.