Package org.fao.geonet.kernel

Examples of org.fao.geonet.kernel.DataManager


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

  public ImportConfig(File configFile, ServiceContext context) throws Exception
  {
    GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
    DataManager   dm = gc.getBean(DataManager.class);

    Element config = Xml.loadFile(configFile);

    fillCategIds(context);
View Full Code Here


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

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

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

        if(context.isDebugEnabled())
            context.debug("Get selected metadata");
    SelectionManager sm = SelectionManager.getManager(session);

    synchronized(sm.getSelection("metadata")) {
    for (Iterator<String> iter = sm.getSelection("metadata").iterator(); iter.hasNext();) {
      String uuid = (String) iter.next();
            if(context.isDebugEnabled())
                context.debug("Deleting metadata with uuid:"+ uuid);

      String id   = dataMan.getMetadataId(uuid);
      //--- Metadata may have been deleted since selection
      if (id != null) {
        //-----------------------------------------------------------------------
        //--- check access
        Element md = dataMan.getMetadataNoInfo(context, id);
 
        if (md == null) {
          notFound.add(Integer.valueOf(id));
        } else if (!accessMan.isOwner(context, id)) {
          notOwner.add(Integer.valueOf(id));
        } else {
 
          //--- now set metadata into subversion repo
          dataMan.versionMetadata(context, id, md);
                    if(context.isDebugEnabled())
                        context.debug("  Metadata with id " + id + " added to subversion repo.");
          metadata.add(Integer.valueOf(id));
        }
      } else
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);
    AccessManager accessMan = gc.getBean(AccessManager.class);

        boolean backupFile = Util.getParam(params, Params.BACKUP_FILE, true);
    String id = Utils.getIdentifierFromParameters(params, context);

        // If send a non existing uuid, Utils.getIdentifierFromParameters returns null
        if (id == null)
            throw new IllegalArgumentException("Metadata internal identifier or UUID not found.");

    //-----------------------------------------------------------------------
    //--- check access

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

    if (metadata == null)
      throw new IllegalArgumentException("Metadata with identifier " + id + " not found.");

    if (!accessMan.canEdit(context, id))
      throw new OperationNotAllowedEx();

    //-----------------------------------------------------------------------
    //--- backup metadata in 'removed' folder

    if (metadata.getDataInfo().getType() != MetadataType.SUB_TEMPLATE && backupFile)
      backupFile(context, id, metadata.getUuid(), MEFLib.doExport(context, metadata.getUuid(), "full", false, true, false));

    //-----------------------------------------------------------------------
    //--- remove the metadata directory including the public and private directories.
    File pb = new File(Lib.resource.getMetadataDir(context, id));
    FileCopyMgr.removeDirectoryOrFile(pb);
   
    //-----------------------------------------------------------------------
    //--- delete metadata and return status

    dataMan.deleteMetadata(context, id);

    Element elResp = new Element(Jeeves.Elem.RESPONSE);
    elResp.addContent(new Element(Geonet.Elem.ID).setText(id));

    return elResp;
View Full Code Here

  {
        AjaxEditUtils ajaxEditUtils = new AjaxEditUtils(context);
        ajaxEditUtils.preprocessUpdate(params, context);

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

    String id         = Utils.getIdentifierFromParameters(params, context);
    String isTemplate = Util.getParam(params, Params.TEMPLATE, "n");
    String showValidationErrors = Util.getParam(params, Params.SHOWVALIDATIONERRORS, "false");
    String data       = params.getChildText(Params.DATA);
        String minor      = Util.getParam(params, Params.MINOREDIT, "false");

    boolean finished = config.getValue(Params.FINISHED, "no").equals("yes");
    boolean forget   = config.getValue(Params.FORGET, "no").equals("yes");


    if (!forget) {
      int iLocalId = Integer.parseInt(id);
      dataMan.setTemplateExt(iLocalId, MetadataType.lookup(isTemplate));

      //--- use StatusActionsFactory and StatusActions class to possibly
      //--- change status as a result of this edit (use onEdit method)
      StatusActionsFactory saf = new StatusActionsFactory(gc.getStatusActionsClass());
      StatusActions sa = saf.createStatusActions(context);
            sa.onEdit(iLocalId, minor.equals("true"));

      if (data != null) {
        Element md = Xml.loadString(data, false);

                String changeDate = null;
                boolean validate = showValidationErrors.equals("true");
                boolean updateDateStamp = !minor.equals("true");
                boolean ufo = true;
                boolean index = true;
        dataMan.updateMetadata(context, id, md, validate, ufo, index, context.getLanguage(), changeDate, updateDateStamp);
      } else {
        ajaxEditUtils.updateContent(params, false, true);
      }
    } else {
      dataMan.cancelEditingSession(context, id);
    }

    //-----------------------------------------------------------------------
    //--- update element and return status

    Element elResp = new Element(Jeeves.Elem.RESPONSE);
    elResp.addContent(new Element(Geonet.Elem.ID).setText(id));
        String tocIndex       = params.getChildText(Geonet.Elem.TOC_INDEX);
        elResp.addContent(new Element(Geonet.Elem.TOC_INDEX).setText(tocIndex));
    elResp.addContent(new Element(Geonet.Elem.SHOWVALIDATIONERRORS).setText(showValidationErrors));
        boolean justCreated = Util.getParam(params, Params.JUST_CREATED, null) != null ;
        if(justCreated) {
            elResp.addContent(new Element(Geonet.Elem.JUSTCREATED).setText("true"));
        }
        elResp.addContent(new Element(Params.MINOREDIT).setText(minor));
       
        //--- if finished then remove the XML from the session
    if (finished) {
      ajaxEditUtils.removeMetadataEmbedded(session, id);
     
      dataMan.endEditingSession(id, session);
    }

    return elResp;
  }
View Full Code Here

    String status = Util.getParam(params, Params.STATUS);
    String changeMessage = Util.getParam(params, Params.CHANGE_MESSAGE);

    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<Integer> notFound = new HashSet<Integer>();
    Set<Integer> notOwner = new HashSet<Integer>();

        final MetadataRepository metadataRepository = context.getBean(MetadataRepository.class);
        synchronized(sm.getSelection("metadata")) {
    for (Iterator<String> iter = sm.getSelection("metadata").iterator(); iter.hasNext();) {
      String uuid = (String) iter.next();
      String id   = dm.getMetadataId(uuid);


            final Integer iId = Integer.valueOf(id);
            if (! metadataRepository.exists(iId)) {
        notFound.add(iId);
View Full Code Here

                                boolean xlinks,
                                boolean reset,
                                boolean fromSelection) throws Exception {
    GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);

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

    try {
      if (reset) {
        synchronized (_tracker) {
              setupIndex(false);
                }
      }
            if (fromSelection) {
                dataMan.rebuildIndexForSelection(context, xlinks);
            } else if (xlinks) {
                dataMan.rebuildIndexXLinkedMetadata(context);
            } else {
                synchronized (_tracker) {
                    setupIndex(true);
                }
                dataMan.init(context, true);
            }
      return true;
    }
        catch (Exception e) {
      Log.error(Geonet.INDEX_ENGINE, "Exception while rebuilding lucene index, going to rebuild it: " +
View Full Code Here

  {
    Element response = new Element("response");

    //--- check access
    GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
    DataManager   dataManager = gc.getBean(DataManager.class);

    boolean addEdit = false;
   
    //--- the request should contain an ID or UUID
    String id = Utils.getIdentifierFromParameters(params, context);

    if (id == null) {
      throw new MetadataNotFoundEx("No record has this UUID");
    }
   
    //--- check download access
    Lib.resource.checkPrivilege(context, id, ReservedOperation.download);

    //--- get metadata
        boolean withValidationErrors = false, keepXlinkAttributes = false;
        Element elMd = dataManager.getMetadata(context, id, addEdit, withValidationErrors, keepXlinkAttributes);

    if (elMd == null) {
      throw new MetadataNotFoundEx("Metadata not found - deleted?");
        }
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);
    AccessManager am = gc.getBean(AccessManager.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);

    //--- only allow the owner of the record to set its status
    if (!am.isOwner(context, id)) {
      throw new UnAuthorizedException("Only the owner of the metadata can set the status. User is not the owner of the metadata", null);
    }

    String status = Util.getParam(params, Params.STATUS);
    String changeMessage = Util.getParam(params, Params.CHANGE_MESSAGE);
    ISODate changeDate = new ISODate();

    //--- use StatusActionsFactory and StatusActions class to
    //--- change status and carry out behaviours for status changes
    StatusActionsFactory saf = new StatusActionsFactory(gc.getStatusActionsClass());

    StatusActions sa = saf.createStatusActions(context);

    Set<Integer> metadataIds = new HashSet<Integer>();
    metadataIds.add(iLocalId);

    sa.statusChange(status, metadataIds, changeDate, changeMessage);

    //--- reindex 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

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

  public Element exec(Element params, ServiceContext context) throws Exception
  {
    GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
    DataManager dataMan = gc.getBean(DataManager.class);
    AccessManager am = gc.getBean(AccessManager.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);

    if (!am.isOwner(context,id))
      throw new IllegalArgumentException("You are not the owner of metadata --> "+id);

    //-----------------------------------------------------------------------
    //--- retrieve metadata status

    MetadataStatus stats = dataMan.getStatus(iLocalId);

    String status = Params.Status.UNKNOWN;
    String userId = "-1"; // no userId
    if (stats != null) {
        status = String.valueOf(stats.getId().getStatusId());
View Full Code Here

            throws Exception {

        Element response = new Element("suggestions");
        GeonetContext gc = (GeonetContext) context
                .getHandlerContext(Geonet.CONTEXT_NAME);
        DataManager dm = gc.getBean(DataManager.class);
        SettingManager sm = gc.getBean(SettingManager.class);

        String action = Util.getParam(params, "action", "list");
        @SuppressWarnings("unchecked")
        List<Element> children = params.getChildren();
        Map<String, Object> xslParameter = new HashMap<String, Object>();
        xslParameter.put("guiLang", context.getLanguage());
        xslParameter.put("siteUrl", sm.getSiteURL(context));
        xslParameter.put("baseUrl", context.getBaseUrl());
        for (Element param : children) {
            xslParameter.put(param.getName(), param.getTextTrim());
        }

        // Retrieve metadata record
        String id = Utils.getIdentifierFromParameters(params, context);
        Metadata mdInfo = gc.getBean(MetadataRepository.class).findOne(id);
        boolean forEditing = false, withValidationErrors = false, keepXlinkAttributes = false;
        Element md = gc.getBean(DataManager.class).getMetadata(context, id, forEditing, withValidationErrors, keepXlinkAttributes);

        // List or analyze all suggestions process registered for this schema
        if ("list".equals(action) || "analyze".equals(action)) {
            MetadataSchema metadataSchema = dm.getSchema(mdInfo.getDataInfo().getSchemaId());
            String filePath = metadataSchema.getSchemaDir() + "/"
                    + XSL_SUGGEST;
            File xslProcessing = new File(filePath);
            if (xslProcessing.exists()) {
                // -- here we send parameters set by user from
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.