Package org.fao.geonet.kernel

Examples of org.fao.geonet.kernel.DataManager


                                    List<String> id, String createDate, String changeDate,
                                    String groupId, MetadataType isTemplate) throws Exception {

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

    if (uuid == null || uuid.equals("")
        || uuidAction.equals(Params.GENERATE_UUID)) {
      String newuuid = UUID.randomUUID().toString();
      source = null;

      Log
          .debug(Geonet.MEF, "Replacing UUID " + uuid + " with "
              + newuuid);
      uuid = newuuid;

      // --- set uuid inside metadata
      md.add(index, dm.setUUID(schema, uuid, md.get(index)));
    } else {
      if (sourceName == null)
        sourceName = "???";

      if (source == null || source.trim().length() == 0)
        throw new Exception(
            "Missing siteId parameter from info.xml file");

      // --- only update sources table if source is not current site
            if (!source.equals(gc.getBean(SettingManager.class).getSiteId())) {
                Source source1 = new Source(source, sourceName, true);
                context.getBean(SourceRepository.class).save(source1);
            }
    }

    try {
      if (dm.existsMetadataUuid(uuid) && !uuidAction.equals(Params.NOTHING)) {
                // user has privileges to replace the existing metadata
                if(dm.getAccessManager().canEdit(context, dm.getMetadataId(uuid))) {
                    dm.deleteMetadata(context, dm.getMetadataId(uuid));
                    if(Log.isDebugEnabled(Geonet.MEF))
                        Log.debug(Geonet.MEF, "Deleting existing metadata with UUID : " + uuid);
                }
                // user does not hav privileges to replace the existing metadata
                else {
                    throw new UnAuthorizedException("User has no privilege to replace existing metadata", null);
                }
      }
    }
        catch (Exception e) {
            throw new Exception(" Existing metadata with UUID " + uuid + " could not be deleted. Error is: " + e.getMessage());
    }



        if(Log.isDebugEnabled(Geonet.MEF))
            Log.debug(Geonet.MEF, "Adding metadata with uuid:" + uuid);
   
        //
        // insert metadata
        //
        int userid = context.getUserSession().getUserIdAsInt();
        String docType = null, title = null, category = null;
        boolean ufo = false, indexImmediate = false;
        id.add(index,
                dm.insertMetadata(context, schema, md.get(index), uuid,
                userid, groupId, source, isTemplate.codeString, docType, category, createDate, changeDate, ufo, indexImmediate));

  }
View Full Code Here


        userGroupRepo.deleteAllByIdAttribute(UserGroupId_.groupId, Arrays.asList(iId));
        groupRepo.delete(iId);
    //--- reindex affected metadata

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


        dm.indexMetadata(Lists.transform(reindex, Functions.toStringFunction()));

        return new Element(Jeeves.Elem.RESPONSE)
              .addContent(new Element(Jeeves.Elem.OPERATION).setText(Jeeves.Text.REMOVED));
  }
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);

    String id = Utils.getIdentifierFromParameters(params, context);

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

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

    Element status = dataMan.getStatus(iLocalId).getAsXml();
        status.setName(Jeeves.Elem.RESPONSE);
    return status;
  }
View Full Code Here

        int sourceGrp = Util.getParamAsInt(params, "sourceGroup");
        int targetUsr = Util.getParamAsInt(params, "targetUser");
        int targetGrp = Util.getParamAsInt(params, "targetGroup");

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

        //--- transfer privileges (if case)

        Set<String> sourcePriv = retrievePrivileges(context, sourceUsr, sourceGrp);
        Set<String> targetPriv = retrievePrivileges(context, null, targetGrp);

        //--- a commit just to release some resources

        dm.flush();

        int privCount = 0;

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

        for (String priv : sourcePriv)
        {
            StringTokenizer st = new StringTokenizer(priv, "|");

            int opId = Integer.parseInt(st.nextToken());
            int mdId = Integer.parseInt(st.nextToken());

            // 2 cases could happen, 1) only the owner change
            // in that case sourceGrp = targetGrp and operations
            // allowed does not need to be modified.
            if (sourceGrp != targetGrp) {
                // 2) the sourceGrp != targetGrp and in that
                // case, all operations need to be transfered to
                // the new group if not already defined.
                dm.unsetOperation(context, mdId, sourceGrp, opId);

                if (!targetPriv.contains(priv)) {
                    OperationAllowedRepository repository = context.getBean(OperationAllowedRepository.class);
                    OperationAllowedId id = new OperationAllowedId()
                            .setGroupId(targetGrp)
                            .setMetadataId(mdId)
                            .setOperationId(opId);
                    OperationAllowed operationAllowed = new OperationAllowed(id );
                    repository.save(operationAllowed);
                }
            }

            // Collect all metadata ids
            metadata.add(mdId);
            privCount++;
        }

        // Set owner for all records to be modified.
        for (Integer i : metadata) {
            final MetadataRepository metadataRepository = context.getBean(MetadataRepository.class);
            final Metadata metadata1 = metadataRepository.findOne(i);
            metadata1.getSourceInfo().setGroupOwner(targetGrp).setOwner(targetUsr);
            metadataRepository.save(metadata1);
        }

        dm.flush();

        //--- reindex metadata
        List<String> list = new ArrayList<String>();
        for (int mdId : metadata) {
            list.add(Integer.toString(mdId));
        }
        dm.indexMetadata(list);

        //--- return summary
        return new Element("response")
                .addContent(new Element("privileges").setText(privCount      +""))
                .addContent(new Element("metadata".setText(metadata.size()+""));
View Full Code Here

   * @return
   * @throws Exception
   */
  public static Element getRelation(int id, String relation, ServiceContext context) throws Exception {
    GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
    DataManager dm = gc.getBean(DataManager.class);
   
    Set<Integer> result = getRelationIds(id, relation, context);
   
        // --- retrieve metadata and return result
    Element response = new Element("response");

    for (Integer mdId : result) {
            boolean forEditing = false, withValidationErrors = false, keepXlinkAttributes = false;
            Element md = dm.getMetadata(context,"" + mdId, forEditing, withValidationErrors, keepXlinkAttributes);

      // --- we could have a race condition so, just perform a simple check
      if (md != null)
        response.addContent(md);
    }
View Full Code Here

    return new Element(Jeeves.Elem.RESPONSE).setText("ok");
  }

  public static void doActions(ServiceContext context) throws Exception {
    GeonetContext  gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
    DataManager    dataMan = gc.getBean(DataManager.class);
    SettingManager settingMan = gc.getBean(SettingManager.class);
    SettingInfo si = context.getBean(SettingInfo.class);

    try {
      if (si.getLuceneIndexOptimizerSchedulerEnabled()) {
        dataMan.rescheduleOptimizer(si.getLuceneIndexOptimizerSchedulerAt(), si.getLuceneIndexOptimizerSchedulerInterval());
      } else {
        dataMan.disableOptimizer();
      }
    } catch (Exception e) {
      e.printStackTrace();
      throw new OperationAbortedEx("Parameters saved but cannot restart Lucene Index Optimizer: "+e.getMessage());
    }
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>();
    Set<Integer> subtemplates = new HashSet<Integer>();

    // Get xpath, extract-title XSLT name, category and test from args
    String xpath = Util.getParam(params, Params.XPATH);

    String getTit = Util.getParam(params, Params.EXTRACT_TITLE, "");
    String xpathTit = Util.getParam(params, Params.XPATH_TITLE, "");
    if (getTit.length() > 0) {
      if (!(new File(getTit).exists())) {
        throw new IllegalArgumentException("Cannot find xslt "+getTit+" to extract a title field from a subtemplate");
      }
    } else {
      if (xpathTit.length() == 0) {
        throw new IllegalArgumentException("Must specify an xpath parameter "+Params.XPATH_TITLE+" or an XSLT file as parameter "+Params.EXTRACT_TITLE+" to select a title field from a subtemplate");
      }
    }
    String uuid = Util.getParam(params, Params.UUID, "");

    String category = Util.getParam(params, Params.CATEGORY);
    String changeParam = Util.getParam(params, Params.DOCHANGES, "off");
    boolean doChanges = changeParam.equals("on");

    if (!(category.equals("_none_")) && category.startsWith("_")) {
      category = category.substring(1);
    } else {
      category = null;
    }

    Element response = new Element(Jeeves.Elem.RESPONSE);

    // --- see if we need to process selected set or just uuid
    if (uuid.length() == 0) { // no uuid so process selected set
      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();) {
        uuid = (String) iter.next();
        processRecord(context, uuid, category, xpath, getTit, xpathTit, doChanges, metadata, notFound, notOwner, subtemplates, response);

      }
      }
      // Clear the selection after extraction
      SelectionManager.updateSelection("metadata", session, params.addContent(new Element("selected").setText("remove-all")), context);

    } else { // just process the uuid passed in
      processRecord(context, uuid, category, xpath, getTit, xpathTit, doChanges, metadata, notFound, notOwner, subtemplates, response);
    }

        dataMan.flush();

        // -- reindex metadata
    context.info("Re-indexing metadata");
    Set<Integer> indexers = new HashSet<Integer>();
    indexers.addAll(metadata);
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);
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 session = context.getUserSession();


        String targetUsr = Util.getParam(params, Params.USER);
        String targetGrp = Util.getParam(params, Params.GROUP);

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

        context.info("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();
                String id = dm.getMetadataId(uuid);

                context.info("Attempting to set metadata owner on: " + id);

                //--- check existence and access
                Metadata info = context.getBean(MetadataRepository.class).findOne(id);

                if (info == null) {
                    notFound.add(Integer.valueOf(id));
                } else if (!accessMan.isOwner(context, id)) {
                    notOwner.add(Integer.valueOf(id));
                } else {

                    //-- Get existing owner and privileges for that owner - note that
                    //-- owners don't actually have explicit permissions - only their
                    //-- group does which is why we have an ownerGroup (parameter groupid)
                    Integer sourceUsr = info.getSourceInfo().getOwner();
                    Integer sourceGrp = info.getSourceInfo().getGroupOwner();
                    Vector<OperationAllowedId> sourcePriv =
                            retrievePrivileges(context, id, "" + sourceUsr, "" + sourceGrp);

                    // -- Set new privileges for new owner from privileges of the old
                    // -- owner, if none then set defaults
                    if (sourcePriv.size() == 0) {
                        dm.copyDefaultPrivForGroup(context, id, targetGrp, false);
                        context.info("No privileges for user " + sourceUsr + " on metadata " + id + ", so setting default privileges");
                    } else {
                        for (OperationAllowedId priv : sourcePriv) {
                            dm.unsetOperation(context, id,
                                    "" + sourceGrp,
                                    "" + priv.getOperationId());
                            dm.setOperation(context, id, targetGrp,
                                    "" + priv.getOperationId());
                        }
                    }
                    // -- set the new owner into the metadata record
                    dm.updateMetadataOwner(Integer.parseInt(id), targetUsr, targetGrp);

                    metadata.add(Integer.valueOf(id));
                }
            }
        }
View Full Code Here

        // Handle children IDs.
        String[] children = childrenIds.split(",");

        // Update children
        GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
        DataManager   dm = gc.getBean(DataManager.class);

        Set<String> untreatedChildren = dm.updateChildren(context, parentUuid, children, parameters);

        Element response = new Element(Jeeves.Elem.RESPONSE);
        int treatedChildren = children.length;
        StringBuilder untreatedReport = new StringBuilder();
        if (untreatedChildren.size() != 0) {
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.