Package org.fao.geonet.domain

Examples of org.fao.geonet.domain.Metadata


     * @throws Exception
     */
    public String createMetadata(ServiceContext context, String templateId, String groupOwner,
                                 String source, int owner,
                                 String parentUuid, String isTemplate, boolean fullRightsForGroup) throws Exception {
        Metadata templateMetadata = _metadataRepository.findOne(templateId);
        if (templateMetadata == null) {
            throw new IllegalArgumentException("Template id not found : " + templateId);
        }

        String schema = templateMetadata.getDataInfo().getSchemaId();
        String data   = templateMetadata.getData();
        String uuid   = UUID.randomUUID().toString();
        Element xml = Xml.loadString(data, false);
        if (templateMetadata.getDataInfo().getType() == MetadataType.METADATA) {
            xml = updateFixedInfo(schema, Optional.<Integer>absent(), uuid, xml, parentUuid, UpdateDatestamp.NO, context);
        }
        final Metadata newMetadata = new Metadata().setUuid(uuid);
        newMetadata.getDataInfo()
                .setChangeDate(new ISODate())
                .setCreateDate(new ISODate())
                .setSchemaId(schema)
                .setType(MetadataType.lookup(isTemplate));
        newMetadata.getSourceInfo()
                .setGroupOwner(Integer.valueOf(groupOwner))
                .setOwner(owner)
                .setSourceId(source);

        Collection<MetadataCategory> filteredCategories = Collections2.filter(templateMetadata.getCategories(),
                new Predicate<MetadataCategory>() {
                    @Override
                    public boolean apply(@Nullable MetadataCategory input) {
                        return input != null;
                    }
                });

        newMetadata.getCategories().addAll(filteredCategories);

        int finalId = insertMetadata(context, newMetadata, xml, false, true, true, UpdateDatestamp.YES,
                fullRightsForGroup, true).getId();

        return String.valueOf(finalId);
View Full Code Here


        }

        if(StringUtils.isBlank(metadataType)) {
            metadataType = MetadataType.METADATA.codeString;
        }
        final Metadata newMetadata = new Metadata().setUuid(uuid);
        final ISODate isoChangeDate = changeDate != null ? new ISODate(changeDate) : new ISODate();
        final ISODate isoCreateDate = createDate != null ? new ISODate(createDate) : new ISODate();
        newMetadata.getDataInfo()
                .setChangeDate(isoChangeDate)
                .setCreateDate(isoCreateDate)
                .setSchemaId(schema)
                .setDoctype(docType)
                .setRoot(metadataXml.getQualifiedName())
                .setType(MetadataType.lookup(metadataType));
        newMetadata.getSourceInfo()
                .setOwner(owner)
                .setSourceId(source);
        if (groupOwner != null) {
            newMetadata.getSourceInfo().setGroupOwner(Integer.valueOf(groupOwner));
        }
        if (category != null) {
            MetadataCategory metadataCategory = _applicationContext.getBean(MetadataCategoryRepository.class).findOneByName(category);
            if (metadataCategory == null) {
                throw new IllegalArgumentException("No category found with name: "+category);
            }
            newMetadata.getCategories().add(metadataCategory);
        }

        boolean fullRightsForGroup = false;

        int finalId = insertMetadata(context, newMetadata, metadataXml, notifyChange, index, ufo, UpdateDatestamp.NO,
View Full Code Here

        String username = session.getUsername();
        if (username == null)
            username = "unknown (this shouldn't happen?)";


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

        String mdUuid =  metadata.getUuid();

        // Jeeves will place the uploaded file name in the f_{ref} element
        // we do it this way because Jeeves will sanitize the name to remove
        // characters that may cause problems
        Element fnameElem = params.getChild("f_" + ref);
View Full Code Here

            String parentUuid = null;
            metadataXml = updateFixedInfo(schema, Optional.<Integer>absent(), newMetadata.getUuid(), metadataXml, parentUuid, updateDatestamp, context);
        }

        //--- store metadata
        final Metadata savedMetadata = xmlSerializer.insert(newMetadata, metadataXml, context);

        final String stringId = String.valueOf(savedMetadata.getId());
        String groupId = null;
        final Integer groupIdI = newMetadata.getSourceInfo().getGroupOwner();
        if (groupIdI != null) {
            groupId = String.valueOf(groupIdI);
        }
View Full Code Here

        //--- force namespace prefix for iso19139 metadata
        setNamespacePrefixUsingSchemas(schema, md);

        // Notifies the metadata change to metatada notifier service
        final Metadata metadata = _metadataRepository.findOne(metadataId);

        String uuid = null;
        if (schemaMan.getSchema(schema).isReadwriteUUID()
                && metadata.getDataInfo().getType() != MetadataType.SUB_TEMPLATE) {
            uuid = extractUUID(schema, metadataXml);
        }

        //--- write metadata to dbms
        xmlSerializer.update(metadataId, metadataXml, changeDate, updateDateStamp, uuid, context);
        if (metadata.getDataInfo().getType() == MetadataType.METADATA) {
            // Notifies the metadata change to metatada notifier service
            notifyMetadataChange(metadataXml, metadataId);
        }

        try {
View Full Code Here

     * @param mdId
     * @param categId
     * @throws Exception
     */
    public void unsetCategory(final ServiceContext context, final String mdId, final int categId) throws Exception {
        Metadata metadata = _metadataRepository.findOne(mdId);

        if (metadata == null) {
            return;
        }
        boolean changed = false;
        for (MetadataCategory category : metadata.getCategories()) {
            if (category.getId() == categId) {
                changed = true;
                metadata.getCategories().remove(category);
                break;
            }
        }

        if (changed) {
View Full Code Here

     * @param mdId
     * @return
     * @throws Exception
     */
    public Collection<MetadataCategory> getCategories(final String mdId) throws Exception {
        Metadata metadata = _metadataRepository.findOne(mdId);
        if (metadata == null) {
            throw new IllegalArgumentException("No metadata found with id: "+mdId);
        }

        return metadata.getCategories();
    }
View Full Code Here

        boolean autoFixing = settingMan.getValueAsBool("system/autofixing/enable", true);
        if(autoFixing) {
            if(Log.isDebugEnabled(Geonet.DATA_MANAGER))
                Log.debug(Geonet.DATA_MANAGER, "Autofixing is enabled, trying update-fixed-info (updateDatestamp: " + updateDatestamp.name() + ")");

            Metadata metadata = null;
            if (metadataId.isPresent()) {
                metadata = _metadataRepository.findOne(metadataId.get());
                boolean isTemplate = metadata != null && metadata.getDataInfo().getType() != MetadataType.METADATA;

                // don't process templates
                if(isTemplate) {
                    if(Log.isDebugEnabled(Geonet.DATA_MANAGER)) {
                        Log.debug(Geonet.DATA_MANAGER, "Not applying update-fixed-info for a template");
                    }
                    return md;
                }
            }

            String currentUuid = metadata != null ? metadata.getUuid() : null;
            String id = metadata != null ? metadata.getId() + "" : null;
            uuid = uuid == null ? currentUuid : uuid;

            //--- setup environment
            Element env = new Element("env");
            env.addContent(new Element("id").setText(id));
View Full Code Here

    for (Iterator<String> iter = sm.getSelection(SELECTION_METADATA).iterator(); iter.hasNext();) {
      String uuid = iter.next();

      //--- check access

      Metadata info = context.getBean(MetadataRepository.class).findOneByUuid(uuid);
      if (info == null) {
        notFound.add(uuid);
      } else if (!accessMan.isOwner(context, String.valueOf(info.getId()))) {
        notOwner.add(info.getId());
      } else {

        //--- remove old operations
        boolean skip = false;

        //--- in case of owner, privileges for groups 0,1 and GUEST are
        //--- disabled and are not sent to the server. So we cannot remove them
        boolean isAdmin = Profile.Administrator == us.getProfile();
        boolean isReviewer= Profile.Reviewer == us.getProfile();

        if (us.getUserIdAsInt() == info.getSourceInfo().getOwner() && !isAdmin && !isReviewer) {
                    skip = true;
                }

        dm.deleteMetadataOper(context, "" + info.getId(), skip);

        //--- set new ones
        @SuppressWarnings("unchecked")
                List<Element> list = params.getChildren();

        for (Element el : list) {
          String name  = el.getName();

          if (name.startsWith("_")) {
            StringTokenizer st = new StringTokenizer(name, "_");

            String groupId = st.nextToken();
            String operId  = st.nextToken();

            dm.setOperation(context, "" + info.getId(), groupId, operId);
          }
        }
        metadata.add(info.getId());
      }
    }
    }

    //--- reindex metadata
View Full Code Here

     * @param version
     * @return
     * @throws Exception
     */
    private Element buildInfoElem(ServiceContext context, String id, String version) throws Exception {
        Metadata metadata = _metadataRepository.findOne(id);
        final MetadataDataInfo dataInfo = metadata.getDataInfo();
        String schema = dataInfo.getSchemaId();
        String createDate = dataInfo.getCreateDate().getDateAndTime();
        String changeDate = dataInfo.getChangeDate().getDateAndTime();
        String source = metadata.getSourceInfo().getSourceId();
        String isTemplate = dataInfo.getType().codeString;
        String title = dataInfo.getTitle();
        String uuid = metadata.getUuid();
        String isHarvested = "" + Constants.toYN_EnabledChar(metadata.getHarvestInfo().isHarvested());
        String harvestUuid = metadata.getHarvestInfo().getUuid();
        String popularity = "" + dataInfo.getPopularity();
        String rating = "" + dataInfo.getRating();
        String owner = "" + metadata.getSourceInfo().getOwner();
        String displayOrder = "" + dataInfo.getDisplayOrder();

        Element info = new Element(Edit.RootChild.INFO, Edit.NAMESPACE);

        addElement(info, Edit.Info.Elem.ID, id);
        addElement(info, Edit.Info.Elem.SCHEMA, schema);
        addElement(info, Edit.Info.Elem.CREATE_DATE, createDate);
        addElement(info, Edit.Info.Elem.CHANGE_DATE, changeDate);
        addElement(info, Edit.Info.Elem.IS_TEMPLATE, isTemplate);
        addElement(info, Edit.Info.Elem.TITLE, title);
        addElement(info, Edit.Info.Elem.SOURCE, source);
        addElement(info, Edit.Info.Elem.UUID, uuid);
        addElement(info, Edit.Info.Elem.IS_HARVESTED, isHarvested);
        addElement(info, Edit.Info.Elem.POPULARITY, popularity);
        addElement(info, Edit.Info.Elem.RATING, rating);
        addElement(info, Edit.Info.Elem.DISPLAY_ORDER, displayOrder);

        if (metadata.getHarvestInfo().isHarvested()) {
            HarvestInfoProvider infoProvider = _applicationContext.getBean(HarvestInfoProvider.class);
            if (infoProvider != null) {
                info.addContent(infoProvider.getHarvestInfo(harvestUuid, id, uuid));
            }
        }
        if (version != null) {
            addElement(info, Edit.Info.Elem.VERSION, version);
        }

        Map<String, Element> map = Maps.newHashMap();
        map.put(id, info);
        buildPrivilegesMetadataInfo(context, map);

        // add owner name
        User user = _applicationContext.getBean(UserRepository.class).findOne(owner);
        if (user != null) {
            String ownerName = user.getName();
            addElement(info, Edit.Info.Elem.OWNERNAME, ownerName);
        }


        for (MetadataCategory category : metadata.getCategories()) {
            addElement(info, Edit.Info.Elem.CATEGORY, category.getName());
        }

        // add subtemplates
        /* -- don't add as we need to investigate indexing for the fields
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.