Package org.fao.geonet.kernel

Examples of org.fao.geonet.kernel.DataManager


    }

    private void removeOldThumbnail(ServiceContext context, String id, String type, boolean indexAfterChange) throws Exception {
        GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);

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

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

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

        result = result.getChild(type);

        //--- if there is no thumbnail, we return

        if (result == null)
            return;

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

        dataMan.unsetThumbnail(context, id, type.equals("small"), indexAfterChange);

        //--- remove file

        String file = Lib.resource.getDir(context, Params.Access.PUBLIC, id) + getFileName(result.getText());
        if (!new File(file).delete())
View Full Code Here


    boolean deleteTempZip = false;

    // -- get the URL of schema zip archive from a metadata record if uuid set
    if (!("".equals(uuid))) {
      GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
      DataManager dm = gc.getBean(DataManager.class);

      String id = dm.getMetadataId(uuid.toLowerCase());
      if (id == null) {
             throw new OperationAbortedEx("Metadata record with uuid "+uuid+" doesn't exist");
      }

      // -- check download permissions (should be ok since admin but...)
      try {
        Lib.resource.checkPrivilege(context, id, ReservedOperation.download);
      }
            catch (Exception e) {
             throw new OperationAbortedEx("Download access not available on metadata record with uuid "+uuid);
      }

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

      if (elMd == null) {
             throw new OperationAbortedEx("Metadata record "+uuid+" doesn't exist");
      }

      // -- transform record into brief version
      Element elBrief = dm.extractSummary(elMd);

      // -- find link using XPath and create URL for further processing
      XPath xp = XPath.newInstance ("link[contains(@protocol,'metadata-schema')]");
      List<?> elems = xp.selectNodes(elBrief);
      try {
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);
    HarvestManager hm = gc.getBean(HarvestManager.class);

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

    String rat = Util.getParam(params, Params.RATING);
    String ip  = context.getIpAddress();

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

    if (ip == null)
      ip = "???.???.???.???";

    if (!Lib.type.isInteger(rat))
      throw new BadParameterEx(Params.RATING, rat);

    int rating = Integer.parseInt(rat);

    if (rating < 1 || rating > 5)
      throw new BadParameterEx(Params.RATING, rat);

    String harvUuid = getHarvestingUuid(context, id);

    // look up value of localrating/enable
    SettingManager settingManager = gc.getBean(SettingManager.class);
    boolean localRating = settingManager.getValueAsBool("system/localrating/enable", false);
   
    if (localRating || harvUuid == null)
      //--- metadata is local, just rate it
      rating = dm.rateMetadata(Integer.valueOf(id), ip, rating);
    else
    {
      //--- the metadata is harvested, is type=geonetwork?

      AbstractHarvester ah = hm.getHarvester(harvUuid);

      if (ah.getType().equals(GeonetHarvester.TYPE)) {
        String uuid = dm.getMetadataUuid(id);
        rating = setRemoteRating(context, (GeonetParams) ah.getParams(), uuid, rating);
      } else {
        rating = -1;
            }
    }
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);

    String id = Utils.getIdentifierFromParameters(params, context);
   
    //-----------------------------------------------------------------------
    //--- check access

    Element md = dataMan.getMetadataNoInfo(context, id);

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

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

    //-----------------------------------------------------------------------
    //--- set metadata into the subversion repo

    dataMan.versionMetadata(context, id, md);

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

    return elResp;
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();

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

        //--- validate metadata from session
        Element errorReport = new AjaxEditUtils(context).validateMetadataEmbedded(session, id, context.getLanguage());

        restructureReportToHavePatternRuleHierarchy(errorReport);

        //--- update element and return status
        Element elResp = new Element(Jeeves.Elem.RESPONSE);
        elResp.addContent(new Element(Geonet.Elem.ID).setText(id));
        elResp.addContent(new Element("schema").setText(dataMan.getMetadataSchema(id)));
        elResp.addContent(errorReport);
        Element schematronTranslations = new Element("schematronTranslations");

        final SchematronRepository schematronRepository = context.getBean(SchematronRepository.class);
        // --- add translations for schematrons
        final List<Schematron> schematrons = schematronRepository.findAllBySchemaName(schemaName);

        MetadataSchema metadataSchema = dataMan.getSchema(schemaName);
        String schemaDir = metadataSchema.getSchemaDir();
        SAXBuilder builder = new SAXBuilder();

        for (Schematron schematron : schematrons) {
            // it contains absolute path to the xsl file
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<Integer> notFound = new HashSet<Integer>();
    Set<Integer> notOwner = new HashSet<Integer>();

    synchronized(sm.getSelection("metadata")) {
    for (Iterator<String> iter = sm.getSelection("metadata").iterator(); iter.hasNext();) {
      String uuid = (String) iter.next();
      String id   = dm.getMetadataId(uuid);
               
      //--- check access

            final MetadataRepository metadataRepository = context.getBean(MetadataRepository.class);
            Metadata info = metadataRepository.findOne(id);
View Full Code Here

    UserSession usrSess = context.getUserSession();
    Profile myProfile = usrSess.getProfile();
    String      myUserId  = usrSess.getUserId();

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

    if (myUserId.equals(id)) {
      throw new IllegalArgumentException("You cannot delete yourself from the user database");
    }

        final UserGroupRepository userGroupRepository = context.getBean(UserGroupRepository.class);
        int iId = Integer.parseInt(id);

    if (myProfile == Profile.Administrator || myProfile == Profile.UserAdmin)  {

      if (myProfile ==  Profile.UserAdmin) {
                final Integer iMyUserId = Integer.valueOf(myUserId);
                final List<Integer> groupIds = userGroupRepository.findGroupIds(where(hasUserId(iMyUserId)).or(hasUserId(iId)));
                if (groupIds.isEmpty()) {
          throw new IllegalArgumentException("You don't have rights to delete this user because the user is not part of your group");
        }
      }

      // Before processing DELETE check that the user is not referenced
      // elsewhere in the GeoNetwork database - an exception is thrown if
      // this is the case
      if (dataMan.isUserMetadataOwner(iId)) {
        throw new IllegalArgumentException("Cannot delete a user that is also a metadata owner");
      }

      if (dataMan.isUserMetadataStatus(iId)) {
        throw new IllegalArgumentException("Cannot delete a user that has set a metadata status");
      }

            userGroupRepository.deleteAllByIdAttribute(UserGroupId_.userId, Arrays.asList(iId));
            context.getBean(UserRepository.class).delete(iId);
View Full Code Here

        //-----------------------------------------------------------------------
    //--- get metadata
        boolean starteditingsession = Util.getParam(params, Params.START_EDITING_SESSION, "no").equals("yes");
        if (starteditingsession) {
          GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
          DataManager   dm = gc.getBean(DataManager.class);
          dm.startEditingSession(context, id);
        }

    Element elMd = new AjaxEditUtils(context).getMetadataEmbedded(context, id, true, showValidationErrors);
    if (elMd == null)
      throw new IllegalArgumentException("Metadata not found --> " + id);
View Full Code Here

public class SaveDisplayOrder implements Service {
  public void init(String appPath, ServiceConfig params) throws Exception {}

  public Element exec(Element params, ServiceContext context) throws Exception {
        GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
        DataManager dm = gc.getBean(DataManager.class) ;
        @SuppressWarnings("unchecked")
        List<Element> requestParameters = params.getChildren();
        List<String> ids = new ArrayList<String>();
        for (Element param : requestParameters) {
            // the request params come in as e.g. <displayorder-30749>5</displayorder-30749> where
            // the part after the dash is the metadata id.
            String id = param.getName().substring(param.getName().indexOf('-') + 1);
            if (StringUtils.isNotEmpty(id) && !"_".equals(id)) {    // In Chrome with POST method, Ajax.Request sends <_/> parameters,
                // If id is not an integer, exception will occur later.
                String displayPosition = param.getText();
                dm.updateDisplayOrder(id, displayPosition);
                ids.add(id);
            }
        }
        dm.indexMetadata(ids);
        return null;
    }
View Full Code Here

    Element result = new Element(Jeeves.Elem.RESPONSE);
    GeonetContext gc = (GeonetContext) context
        .getHandlerContext(Geonet.CONTEXT_NAME);

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

        String siteId = gc.getBean(SettingManager.class).getSiteId();
    int owner = context.getUserSession().getUserIdAsInt();

    Log.info(Geonet.DATA_MANAGER, "Loading templates for schemas "
        + schemaList);
    String schemas[] = schemaList.split(",");

    for (String schemaName : schemas) {

      Element schema = new Element(schemaName);

      String schemaDir = schemaMan.getSchemaTemplatesDir(schemaName);
      if (schemaDir == null) {
        Log.error(Geonet.DATA_MANAGER, "Skipping - No templates?");
        continue;
      }

      File templateFiles[] = new File(schemaDir).listFiles();
      List<File> templateFilesList = new ArrayList<File>();

      if (templateFiles != null) {
        for (File file : templateFiles)
          if (file.getName().endsWith(".xml"))
            templateFilesList.add(file);
      }

            final String prefix = "sub-";
            final int prefixLength = prefix.length();
            for (File temp : templateFilesList) {
                String status = "failed";
                String templateName = temp.getName();

                Element template = new Element("template");
                template.setAttribute("name", templateName);

                if (Log.isDebugEnabled(Geonet.DATA_MANAGER)) {
                    Log.debug(Geonet.DATA_MANAGER,
                            " - Adding template file (for schema " + schemaName + "): " + templateName);
                }

                try {
                    Element xml = Xml.loadFile(temp);
                    String uuid = UUID.randomUUID().toString();
                    String isTemplate = "y";
                    String title = null;

                    if (templateName.startsWith(prefix)) {
            isTemplate = "s";
            title = templateName.substring(prefixLength,
                templateName.length() - prefixLength);
          }
                    //
                    // insert metadata
                    //
                    String groupOwner = "1";
                    String docType = null, category = null, createDate = null, changeDate = null;
                    boolean ufo = true, indexImmediate = true;
          dataMan.insertMetadata(context, schemaName, xml, uuid, owner, groupOwner, siteId,
                                           isTemplate, docType, category, createDate, changeDate, ufo, indexImmediate);

          status = "loaded";
        } catch (Exception e) {
          serviceStatus = "false";
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.