Package org.fao.geonet.kernel

Examples of org.fao.geonet.kernel.DataManager


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

  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);
    UserSession us = context.getUserSession();

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

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

    //-----------------------------------------------------------------------
    //--- run through the selected set of metadata records
    synchronized(sm.getSelection("metadata")) {
    for (Iterator<String> iter = sm.getSelection("metadata").iterator(); iter.hasNext();) {
      String uuid = (String) iter.next();
      String id   = dataMan.getMetadataId(uuid);

      //--- check access, if owner then process
     
      if (am.isOwner(context, id)) {
        ids.add(Integer.valueOf(id));
View Full Code Here


  protected String getMetadataSchema(Element params, ServiceContext context)
      throws Exception {
    String metadataId = Utils.getIdentifierFromParameters(params, context);
      GeonetContext gc = (GeonetContext) context
        .getHandlerContext(Geonet.CONTEXT_NAME);
    DataManager dm = gc.getBean(DataManager.class);
    String schema = dm.getMetadataSchema(metadataId);
    return schema;
  }
View Full Code Here

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

  private int standardImport(Element params, ServiceContext context) throws Exception
  {
    GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
    DataManager   dm = gc.getBean(DataManager.class);

    String dir      = Util.getParam(params, Params.DIR);
    boolean recurse = Util.getParam(params, Params.RECURSE, "off").equals("on");
   
    List<File> files = IO.getFilesInDirectory(new File(dir), recurse, new BatchImportFilenameFilter(recurse));
View Full Code Here

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

  private int configImport(Element params, ServiceContext context, File configFile) throws Exception
  {
    GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
    DataManager   dm = gc.getBean(DataManager.class);

    ImportConfig config = new ImportConfig(configFile, context);

    String dir   = Util.getParam(params, Params.DIR);
    String group = Util.getParam(params, Params.GROUP);
    String style = Util.getParam(params, Params.STYLESHEET);

    boolean validate = Util.getParam(params, Params.VALIDATE, "off").equals("on");

    File sites[] = new File(dir).listFiles(filter);

    if (sites == null)
      throw new Exception("Directory not found : " + dir);

    int counter = 0;

    ArrayList<ImportInfo> alImport = new ArrayList<ImportInfo>();

    for(int i=0; i<sites.length; i++)
    {
            if(context.isDebugEnabled())
                context.debug("Scanning site : "+sites[i]);

      File categs[] = sites[i].listFiles(filter);

      if (categs == null)
        throw new Exception("Cannot scan categories in : " + sites[i].getPath());

      for(int j=0; j<categs.length; j++)
      {
                if(context.isDebugEnabled())
                    context.debug("   Scanning category : "+categs[j]);

        String catDir  = categs[j].getName();
        File   files[] = categs[j].listFiles(new BatchImportFilenameFilter());

        if (files == null)
          throw new Exception("Cannot scan files in : " + categs[j].getPath());

        for(int k=0; k<files.length; k++)
        {
          Element xml = Xml.loadFile(files[k]);

          if (!style.equals("_none_"))
            xml = Xml.transform(xml, stylePath +"/"+ style);

          String category = config.mapCategory(catDir);
          String schema   = config.mapSchema(catDir);

          if (validate)
            dm.validate(schema, xml);

          alImport.add(new ImportInfo(schema, category, xml));
          counter++;
        }
      }
View Full Code Here

  private void insert(String schema, Element xml, String group, ServiceContext context,
                String category) throws Exception
  {
    GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
    DataManager   dm = gc.getBean(DataManager.class);

    //-----------------------------------------------------------------------
    //--- if the uuid does not exist we generate it

    String uuid = dm.extractUUID(schema, xml);

    if (uuid.length() == 0)
      uuid = UUID.randomUUID().toString();

    if (category.equals("_none_")) category = null;
    //-----------------------------------------------------------------------
    //--- insert metadata into the system

        String docType = null, title = null, createDate = null, changeDate = null;
        boolean ufo = true, indexImmediate = true;
        String isTemplate = "n";
        dm.insertMetadata(context, schema, xml, uuid, context.getUserSession().getUserIdAsInt(), group, gc.getBean(SettingManager
                .class).getSiteId(),
                         isTemplate, docType, category, createDate, changeDate, ufo, indexImmediate);

  }
View Full Code Here

                        final String metadataCategory = metadataCategoryRepository.findAll().get(0).getName();
                        final Element sampleMetadataXml = getSampleMetadataXml();
                        final UserSession userSession = serviceContext.getUserSession();
                        final int userIdAsInt = userSession.getUserIdAsInt();
                        final DataManager dm = DataManagerWorksWithoutTransactionIntegrationTest.this.dataManager;
                        String schema = dm.autodetectSchema(sampleMetadataXml);
                        final String mdId = dm.insertMetadata(serviceContext, schema, sampleMetadataXml,
                                "uuid" + _inc.incrementAndGet(), userIdAsInt, "2", "source",
                                MetadataType.METADATA.codeString, null, metadataCategory, new ISODate().getDateAndTime(),
                                new ISODate().getDateAndTime(), false, false);
                        Element newMd = new Element(sampleMetadataXml.getName(), sampleMetadataXml.getNamespace()).addContent(new Element("fileIdentifier",
                                GMD).addContent(new Element("CharacterString", GCO)));

                        Metadata updateMd = dm.updateMetadata(serviceContext, mdId, newMd, false, false, false, "eng",
                                new ISODate().getDateAndTime(), false);
                        assertNotNull(updateMd);
                        final boolean hasNext = updateMd.getCategories().iterator().hasNext();
                        assertTrue(hasNext);
                    }
View Full Code Here

                        final DataManagerWorksWithoutTransactionIntegrationTest test =
                                DataManagerWorksWithoutTransactionIntegrationTest.this;
                        final int metadataId =  DataManagerIntegrationTest.importMetadata(test, serviceContext);

                        final DataManager dm = DataManagerWorksWithoutTransactionIntegrationTest.this.dataManager;
                        DataManagerIntegrationTest.doSetHarvesterDataTest(DataManagerWorksWithoutTransactionIntegrationTest.this.metadataRepository, dm, metadataId);
                    }
                });

    }
View Full Code Here

     * @throws Exception
     */
    public int importMetadataXML(ServiceContext context, String uuid, InputStream xmlInputStream, MetadataType metadataType,
                                 int groupId, String uuidAction) throws Exception {
        final Element metadata = Xml.loadStream(xmlInputStream);
        final DataManager dataManager = _applicationContext.getBean(DataManager.class);
        String schema = dataManager.autodetectSchema(metadata);
        final SourceRepository sourceRepository = _applicationContext.getBean(SourceRepository.class);
        List<Source> sources = sourceRepository.findAll();

        if (sources.isEmpty()) {
            final Source source = sourceRepository.save(new Source().setLocal(true).setName("localsource").setUuid("uuidOfLocalSorce"));
            sources = Lists.newArrayList(source);
        }

        Source source = sources.get(0);
        ArrayList<String> id = new ArrayList<String>(1);
        String createDate = new ISODate().getDateAndTime();
        Importer.importRecord(uuid,
                uuidAction, Lists.newArrayList(metadata), schema, 0,
                source.getUuid(), source.getName(), context,
                id, createDate, createDate,
                "" + groupId, metadataType);

        dataManager.indexMetadata(id.get(0), true);
        return Integer.parseInt(id.get(0));
    }
View Full Code Here

    public Element execute(Element request, ServiceContext context) throws CatalogException {
        String timeStamp = new ISODate().toString();
       
        // Return exception is indexing.
        GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
        DataManager dataManager = gc.getBean(DataManager.class);
        if (dataManager.isIndexing()) {
            throw new RuntimeException("Catalog is indexing records, retry later.");
        }
       
        //
        // some validation checks (note: this is not an XSD validation)
View Full Code Here

                else {
                    if(Log.isDebugEnabled(Geonet.CSW_SEARCH))
                        Log.debug(Geonet.CSW_SEARCH, "adding the complete metadata to results");
                    if(strategy.equals("csw202")) {
                        GeonetContext geonetContext = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
                        DataManager dataManager = geonetContext.getBean(DataManager.class);
                        boolean valid = dataManager.validate(result);
                        if(Log.isDebugEnabled(Geonet.CSW_SEARCH))
                            Log.debug(Geonet.CSW_SEARCH, "strategy csw202: only valid metadata is returned. This one is valid? " + valid);

                        if(!valid) {
                            return null;
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.