Package org.fao.geonet.domain

Examples of org.fao.geonet.domain.Metadata


        assertNull(_repo.findOneByUuid("wrong uuid"));
    }

    @Test
    public void testFindAllIdsBy() throws Exception {
        Metadata metadata = _repo.save(newMetadata());
        _repo.save(newMetadata());
        _repo.save(newMetadata());

        assertEquals(3, _repo.count());

        List<Integer> ids = _repo.findAllIdsBy(MetadataSpecs.hasMetadataUuid(metadata.getUuid()));

        assertArrayEquals(new Integer[]{metadata.getId()}, ids.toArray(new Integer[1]));
    }
View Full Code Here


    }

    @Test
    public void testFindByIdString() throws Exception {

        Metadata metadata = _repo.save(newMetadata());

        _repo.flush();
        _entityManager.flush();
        _entityManager.clear();

        assertEquals(1, _repo.count());

        assertSameContents(metadata, _repo.findOne(String.valueOf(metadata.getId())));

        assertNull(_repo.findOne("213213215"));
    }
View Full Code Here

    }

    @Test
    public void testFindAllByHarvestInfo_Uuid() throws Exception {

        Metadata metadata = _repo.save(newMetadata());
        Metadata metadata2 = _repo.save(newMetadata());
        Metadata metadata3 = newMetadata();
        metadata3.getHarvestInfo().setUuid(metadata2.getHarvestInfo().getUuid());
        _repo.save(metadata3);

        assertEquals(3, _repo.count());

        List<Metadata> found = _repo.findAllByHarvestInfo_Uuid(metadata.getHarvestInfo().getUuid());
View Full Code Here

    }

    @Test
    public void testFindOneOldestByChangeDate() throws Exception {

        Metadata metadata1 = newMetadata();
        metadata1.getDataInfo().setChangeDate(new ISODate("1960-01-01"));
        _repo.save(metadata1);

        Metadata metadata2 = newMetadata();
        metadata2.getDataInfo().setChangeDate(new ISODate("1920-01-01"));
        _repo.save(metadata2);

        assertEquals(2, _repo.count());

        Metadata found = _repo.findOneOldestByChangeDate();
        assertNotNull(found);
        assertSameContents(metadata1, found);
    }
View Full Code Here

    }

    @Test
    public void testFindAllIdsAndChangeDates() throws Exception {

        Metadata metadata = _repo.save(updateChangeDate(newMetadata(), "1990-12-13"));
        Metadata metadata2 = _repo.save(updateChangeDate(newMetadata(), "1980-12-13"));
        Metadata metadata3 = _repo.save(updateChangeDate(newMetadata(), "1995-12-13"));

        final Sort sortByIdAsc = new Sort(Sort.Direction.DESC, Metadata_.id.getName());
        PageRequest page1 = new PageRequest(0, 2, sortByIdAsc);
        PageRequest page2 = new PageRequest(1, 2, sortByIdAsc);
        Page<Pair<Integer, ISODate>> firstPage = _repo.findAllIdsAndChangeDates(page1);
        Page<Pair<Integer, ISODate>> secondPage = _repo.findAllIdsAndChangeDates(page2);

        assertEquals(2, firstPage.getNumberOfElements());
        assertEquals(0, firstPage.getNumber());
        assertEquals(2, firstPage.getTotalPages());
        assertEquals(3, firstPage.getTotalElements());
        assertTrue(firstPage.isFirstPage());
        assertFalse(firstPage.isLastPage());
        assertTrue(firstPage.hasContent());

        assertEquals(1, secondPage.getNumberOfElements());
        assertEquals(1, secondPage.getNumber());
        assertEquals(2, secondPage.getTotalPages());
        assertEquals(3, secondPage.getTotalElements());
        assertFalse(secondPage.isFirstPage());
        assertTrue(secondPage.isLastPage());
        assertTrue(secondPage.hasContent());

        assertEquals((Integer) metadata3.getId(), firstPage.getContent().get(0).one());
        assertEquals((Integer) metadata2.getId(), firstPage.getContent().get(1).one());
        assertEquals((Integer) metadata.getId(), secondPage.getContent().get(0).one());

        assertEquals(metadata3.getDataInfo().getChangeDate(), firstPage.getContent().get(0).two());
        assertEquals(metadata2.getDataInfo().getChangeDate(), firstPage.getContent().get(1).two());
        assertEquals(metadata.getDataInfo().getChangeDate(), secondPage.getContent().get(0).two());

        final Sort sortByChangeDate = SortUtils.createSort(Metadata_.dataInfo, MetadataDataInfo_.changeDate);
        page1 = new PageRequest(0, 1, sortByChangeDate);
        page2 = new PageRequest(0, 3, sortByChangeDate);
        firstPage = _repo.findAllIdsAndChangeDates(page1);
        secondPage = _repo.findAllIdsAndChangeDates(page2);

        assertEquals(1, firstPage.getNumberOfElements());
        assertEquals(3, secondPage.getNumberOfElements());

        assertEquals((Integer) metadata2.getId(), firstPage.getContent().get(0).one());
        assertEquals((Integer) metadata2.getId(), secondPage.getContent().get(0).one());
        assertEquals((Integer) metadata.getId(), secondPage.getContent().get(1).one());
        assertEquals((Integer) metadata3.getId(), secondPage.getContent().get(2).one());

        assertEquals(metadata2.getDataInfo().getChangeDate(), firstPage.getContent().get(0).two());
        assertEquals(metadata2.getDataInfo().getChangeDate(), secondPage.getContent().get(0).two());
        assertEquals(metadata.getDataInfo().getChangeDate(), secondPage.getContent().get(1).two());
        assertEquals(metadata3.getDataInfo().getChangeDate(), secondPage.getContent().get(2).two());
    }
View Full Code Here

        assertEquals(metadata3.getDataInfo().getChangeDate(), secondPage.getContent().get(2).two());
    }

    @Test
    public void testFindAllSourceInfo() throws Exception {
        Metadata metadata = _repo.save(newMetadata());
        Metadata metadata2 = _repo.save(newMetadata());
        Metadata metadata3 = _repo.save(newMetadata());

        final Specification<Metadata> spec = MetadataSpecs.hasMetadataIdIn(Arrays.asList(metadata.getId(), metadata3.getId()));
        final Map<Integer, MetadataSourceInfo> allSourceInfo = _repo.findAllSourceInfo(Specifications.where(spec));

        assertEquals(2, allSourceInfo.size());
        assertTrue(allSourceInfo.containsKey(metadata.getId()));
        assertFalse(allSourceInfo.containsKey(metadata2.getId()));
        assertTrue(allSourceInfo.containsKey(metadata3.getId()));

        assertNotNull(allSourceInfo.get(metadata.getId()));
        assertNull(allSourceInfo.get(metadata2.getId()));
        assertNotNull(allSourceInfo.get(metadata3.getId()));
    }
View Full Code Here

     *
     * @param inc an atomic integer for making each creation different from others.
     */
    public static Metadata newMetadata(AtomicInteger inc) {
        int val = inc.incrementAndGet();
        Metadata metadata = new Metadata().setUuid("uuid" + val).setData("<md>metadata" + val + "</md>");
        metadata.getDataInfo().setSchemaId("customSchema" + val);
        metadata.getSourceInfo().setSourceId("source" + val);
        metadata.getHarvestInfo().setUuid("huuid" + val);
        metadata.getHarvestInfo().setHarvested(val % 2 == 0);
        return metadata;
    }
View Full Code Here

      String uuid, ZipOutputStream zos, boolean skipUUID,
      String stylePath, Format format, boolean resolveXlink, boolean removeXlinkAttribute) throws Exception {

    MEFLib.createDir(zos, uuid + FS);

    Metadata record = MEFLib.retrieveMetadata(context, uuid, resolveXlink, removeXlinkAttribute);

    String id = "" + record.getId();
    String isTemp = record.getDataInfo().getType().codeString;

    if (!"y".equals(isTemp) && !"n".equals(isTemp))
      throw new Exception("Cannot export sub template");

    String pubDir = Lib.resource.getDir(context, "public", id);
    String priDir = Lib.resource.getDir(context, "private", id);

    // --- create folders
    MEFLib.createDir(zos, uuid + FS + DIR_PUBLIC);
    MEFLib.createDir(zos, uuid + FS + DIR_PRIVATE);

        Collection<ExportFormat> formats = context.getApplicationContext().getBeansOfType(ExportFormat.class).values();
        for (ExportFormat exportFormat : formats) {
            for (Pair<String, String> output : exportFormat.getFormats(context, record)) {
                MEFLib.addFile(zos,uuid + FS + MD_DIR + output.one(), output.two());
            }
        }

    // --- save native metadata
    String data = ExportFormat.formatData(record, false, "");
    MEFLib.addFile(zos, uuid + FS + MD_DIR + FILE_METADATA, data);

    // --- save Feature Catalog
    String ftUUID = getFeatureCatalogID(context, record.getId());
    if (!ftUUID.equals("")) {
      Metadata ft = MEFLib.retrieveMetadata(context, ftUUID, resolveXlink, removeXlinkAttribute);
      String ftData = ExportFormat.formatData(ft, false, "");
      MEFLib.addFile(zos, uuid + FS + SCHEMA + FILE_METADATA, ftData);
    }

    // --- save info file
View Full Code Here

   * @return the path of the generated MEF file.
   * @throws Exception
   */
  public static String doExport(ServiceContext context, String uuid,
      Format format, boolean skipUUID, boolean resolveXlink, boolean removeXlinkAttribute) throws Exception {
    Metadata record = MEFLib.retrieveMetadata(context, uuid, resolveXlink, removeXlinkAttribute);

    if (record.getDataInfo().getType() == MetadataType.SUB_TEMPLATE) {
      throw new Exception("Cannot export sub template");
        }

    File file = File.createTempFile("mef-", ".mef");
    String pubDir = Lib.resource.getDir(context, "public", record.getId());
    String priDir = Lib.resource.getDir(context, "private", record.getId());

    FileOutputStream fos = new FileOutputStream(file);
    ZipOutputStream zos = new ZipOutputStream(fos);

    // --- create folders

    MEFLib.createDir(zos, DIR_PUBLIC);
    MEFLib.createDir(zos, DIR_PRIVATE);

    // --- save metadata

    if (!record.getData().startsWith("<?xml")) {
      record.setData("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n" + record.getData());
        }

    byte[] binData = record.getData().getBytes(Constants.ENCODING);

    MEFLib.addFile(zos, FILE_METADATA, new ByteArrayInputStream(binData));

    // --- save info file

    binData = MEFLib.buildInfoFile(context, record, format, pubDir, priDir,
        skipUUID).getBytes(Constants.ENCODING);

    MEFLib.addFile(zos, FILE_INFO, new ByteArrayInputStream(binData));

    // --- save thumbnails and maps

    if (format == Format.PARTIAL || format == Format.FULL)
      MEFLib.savePublic(zos, pubDir, null);

    if (format == Format.FULL) {
      try {
                Lib.resource.checkPrivilege(context, "" + record.getId(), ReservedOperation.download);
        MEFLib.savePrivate(zos, priDir, null);
      } catch (Exception e) {
        // Current user could not download private data
                Log.warning(Geonet.MEF, "Error encounteres while trying to import private resources of MEF file. MEF UUID: "+uuid, e);
      }
View Full Code Here

        //
        boolean validate = false;
        boolean ufo = false;
        boolean index = false;
        String language = context.getLanguage();
                final Metadata metadata = dataMan.updateMetadata(context, id, md, validate, ufo, index, language, ri.changeDate, false);

                OperationAllowedRepository repository = context.getBean(OperationAllowedRepository.class);
                repository.deleteAllByIdAttribute(OperationAllowedId_.metadataId, Integer.parseInt(id));
                addPrivileges(id, params.getPrivileges(), localGroups, dataMan, context, log);

                metadata.getCategories().clear();
                addCategories(metadata, params.getCategories(), localCateg, context, log, null);
                dataMan.flush();

                dataMan.indexMetadata(id, false);
        result.updatedMetadata++;
View Full Code Here

TOP

Related Classes of org.fao.geonet.domain.Metadata

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.