Skip to content
Permalink
Browse files

Draft working with tests. Select buckets still not compatible

  • Loading branch information
Delawen committed Nov 23, 2018
1 parent f165b34 commit dfa497bfbdb9f19545d7284b9cc2e6a9b1010dc4
Showing with 888 additions and 121 deletions.
  1. +3 −0 .gitignore
  2. +77 −2 core/src/main/java/org/fao/geonet/kernel/AccessManager.java
  3. +5 −0 core/src/main/java/org/fao/geonet/kernel/datamanager/base/BaseMetadataManager.java
  4. +12 −5 core/src/main/java/org/fao/geonet/kernel/datamanager/base/BaseMetadataValidator.java
  5. +35 −28 core/src/main/java/org/fao/geonet/kernel/datamanager/draft/DraftMetadataIndexer.java
  6. +113 −60 core/src/main/java/org/fao/geonet/kernel/datamanager/draft/DraftMetadataUtils.java
  7. +32 −2 core/src/main/java/org/fao/geonet/kernel/metadata/DefaultStatusActions.java
  8. +1 −0 core/src/main/java/org/fao/geonet/kernel/search/IndexFields.java
  9. +6 −0 core/src/test/resources/draft-test-context.xml
  10. +56 −0 events/src/main/java/org/fao/geonet/events/md/MetadataStatusChanged.java
  11. +12 −2 events/src/main/java/org/fao/geonet/events/md/sharing/MetadataShare.java
  12. +218 −0 listeners/src/main/java/org/fao/geonet/listener/metadata/draft/ApproveRecord.java
  13. +121 −0 listeners/src/main/java/org/fao/geonet/listener/metadata/draft/UpdateOperations.java
  14. +28 −0 services/src/main/java/org/fao/geonet/api/ApiUtils.java
  15. +9 −8 services/src/main/java/org/fao/geonet/api/records/MetadataWorkflowApi.java
  16. +51 −7 web-ui/src/main/resources/catalog/components/search/mdview/mdviewService.js
  17. +2 −2 web-ui/src/main/resources/catalog/components/search/resultsview/partials/viewtemplates/editor.html
  18. +9 −1 web-ui/src/main/resources/catalog/components/search/resultsview/partials/viewtemplates/grid.html
  19. +8 −2 web-ui/src/main/resources/catalog/components/search/searchmanager/LocationService.js
  20. +2 −0 web-ui/src/main/resources/catalog/js/GnSearchModule.js
  21. +39 −0 web-ui/src/main/resources/catalog/style/gn.less
  22. +1 −1 web-ui/src/main/resources/catalog/views/default/directives/partials/mdactionmenu.html
  23. +37 −0 web-ui/src/main/resources/catalog/views/default/less/gn_results_default.less
  24. +2 −0 web-ui/src/main/resources/catalog/views/default/templates/index.html
  25. +9 −1 web-ui/src/main/resources/catalog/views/default/templates/recordView.html
@@ -78,3 +78,6 @@ schemas/*/doc/*/*.rst
*.old
web-ui-docs/package-lock.json
release/jetty/*
chromedriver
node_modules
package-lock.json
@@ -36,8 +36,8 @@

import org.apache.commons.lang.StringUtils;
import org.fao.geonet.ApplicationContextHolder;
import org.fao.geonet.domain.Group;
import org.fao.geonet.domain.AbstractMetadata;
import org.fao.geonet.domain.Group;
import org.fao.geonet.domain.MetadataSourceInfo;
import org.fao.geonet.domain.Operation;
import org.fao.geonet.domain.OperationAllowed;
@@ -53,7 +53,6 @@
import org.fao.geonet.kernel.setting.Settings;
import org.fao.geonet.repository.GroupRepository;
import org.fao.geonet.repository.GroupRepositoryCustom;
import org.fao.geonet.repository.MetadataRepository;
import org.fao.geonet.repository.OperationAllowedRepository;
import org.fao.geonet.repository.OperationRepository;
import org.fao.geonet.repository.SettingRepository;
@@ -242,6 +241,26 @@ public boolean canEdit(final ServiceContext context, final String id) throws Exc
return isOwner(context, id) || hasEditPermission(context, id);
}

/**
* Returns true if, and only if, at least one of these conditions is satisfied: <ul> <li>the
* user is owner (@see #isOwner)</li> <li>the user has reviewing rights over the metadata</li> </ul>
*
* @param id The metadata internal identifier
*/
public boolean canReview(final ServiceContext context, final String id) throws Exception {
return isOwner(context, id) || hasReviewPermission(context, id);
}

/**
* Returns true if, and only if, at least one of these conditions is satisfied: <ul> <li>the
* user is owner (@see #isOwner)</li> <li>the user has reviewing rights over owning group of the metadata</li> </ul>
*
* @param id The metadata internal identifier
*/
public boolean canChangeStatus(final ServiceContext context, final String id) throws Exception {
return hasOnwershipReviewPermission(context, id) || hasReviewPermission(context, id);
}

/**
* Return true if the current user is: <ul> <li>administrator</li> <li>the metadata owner (the
* user who created the record)</li> <li>reviewer in the group the metadata was created</li>
@@ -432,6 +451,62 @@ public boolean hasEditPermission(final ServiceContext context, final String id)

return (!userGroupRepository.findAll(spec).isEmpty());
}

/**
* Check if current user can review the metadata according to the groups where the metadata is
* editable.
*
* @param id The metadata internal identifier
*/
public boolean hasReviewPermission(final ServiceContext context, final String id) throws Exception {
UserSession us = context.getUserSession();
if (us == null || !us.isAuthenticated())
return false;


OperationAllowedRepository opAllowedRepository = context.getBean(OperationAllowedRepository.class);
UserGroupRepository userGroupRepository = context.getBean(UserGroupRepository.class);
List<OperationAllowed> allOpAlloweds = opAllowedRepository.findAll(where(hasMetadataId(id)).and(hasOperation(ReservedOperation
.editing)));
if (allOpAlloweds.isEmpty()) {
return false;
}

Specifications spec = where(UserGroupSpecs.hasProfile(Profile.Reviewer)).and(UserGroupSpecs.hasUserId(us.getUserIdAsInt()));

List<Integer> opAlloweds = new ArrayList<Integer>();
for (OperationAllowed opAllowed : allOpAlloweds) {
opAlloweds.add(opAllowed.getId().getGroupId());
}
spec = spec.and(UserGroupSpecs.hasGroupIds(opAlloweds));

return (!userGroupRepository.findAll(spec).isEmpty());
}

/**
* Check if current user is reviewer of the owner group for this metadata
*
* @param id The metadata internal identifier
*/
public boolean hasOnwershipReviewPermission(final ServiceContext context, final String id) throws Exception {
UserSession us = context.getUserSession();
if (us == null || !us.isAuthenticated())
return false;


OperationAllowedRepository opAllowedRepository = context.getBean(OperationAllowedRepository.class);
UserGroupRepository userGroupRepository = context.getBean(UserGroupRepository.class);
IMetadataUtils metadataUtils = context.getBean(IMetadataUtils.class);

Specifications spec = where(UserGroupSpecs.hasProfile(Profile.Reviewer)).and(UserGroupSpecs.hasUserId(us.getUserIdAsInt()));

List<Integer> opAlloweds = new ArrayList<Integer>();
opAlloweds.add(metadataUtils.findOne(id).getSourceInfo().getGroupOwner());

spec = spec.and(UserGroupSpecs.hasGroupIds(opAlloweds));

return (!userGroupRepository.findAll(spec).isEmpty());
}

/**
* TODO javadoc.
@@ -81,6 +81,7 @@
import org.fao.geonet.repository.specification.MetadataFileUploadSpecs;
import org.fao.geonet.repository.specification.MetadataSpecs;
import org.fao.geonet.repository.specification.OperationAllowedSpecs;
import org.fao.geonet.utils.Log;
import org.fao.geonet.utils.Xml;
import org.jdom.Element;
import org.jdom.JDOMException;
@@ -756,6 +757,8 @@ public void apply(@Nonnull Metadata entity) {
public synchronized AbstractMetadata updateMetadata(final ServiceContext context, final String metadataId,
final Element md, final boolean validate, final boolean ufo, final boolean index, final String lang,
final String changeDate, final boolean updateDateStamp) throws Exception {
Log.trace(Geonet.DATA_MANAGER, "Update record with id " + metadataId);

Element metadataXml = md;

// when invoked from harvesters, session is null?
@@ -814,6 +817,8 @@ public synchronized AbstractMetadata updateMetadata(final ServiceContext context
list.add(id);
}
}

Log.trace(Geonet.DATA_MANAGER, "Finishing update of record with id " + metadataId);
// Return an up to date metadata record
return metadataUtils.findOne(metadataId);
}
@@ -22,6 +22,7 @@
import org.fao.geonet.kernel.schema.MetadataSchema;
import org.fao.geonet.kernel.setting.SettingManager;
import org.fao.geonet.repository.MetadataValidationRepository;
import org.fao.geonet.utils.Log;
import org.fao.geonet.utils.Xml;
import org.fao.geonet.utils.XmlErrorHandler;
import org.jdom.Attribute;
@@ -209,11 +210,17 @@ public void setNamespacePrefix(final Element md, final Namespace ns) {
*/
@Override
public void validate(String schema, Element md) throws Exception {
XmlErrorHandler eh = new XmlErrorHandler();
Element xsdErrors = validateInfo(schema, md, eh);
if (xsdErrors != null) {
throw new XSDValidationErrorEx("XSD Validation error(s):\n" + Xml.getString(xsdErrors), xsdErrors);
}

if(Log.isTraceEnabled(Geonet.DATA_MANAGER)) {
Log.trace(Geonet.DATA_MANAGER, "Validating record ");
Log.trace(Geonet.DATA_MANAGER, (new org.jdom.output.XMLOutputter()).outputString(md));
}

XmlErrorHandler eh = new XmlErrorHandler();
Element xsdErrors = validateInfo(schema, md, eh);
if (xsdErrors != null) {
throw new XSDValidationErrorEx("XSD Validation error(s):\n" + Xml.getString(xsdErrors), xsdErrors);
}
}

private Element validateInfo(String schema, Element md, XmlErrorHandler eh) throws Exception {
@@ -9,39 +9,46 @@
import org.fao.geonet.kernel.datamanager.base.BaseMetadataIndexer;
import org.fao.geonet.kernel.search.SearchManager;
import org.fao.geonet.repository.MetadataDraftRepository;
import org.fao.geonet.utils.Log;
import org.jdom.Element;
import org.springframework.beans.factory.annotation.Autowired;

import jeeves.server.context.ServiceContext;

public class DraftMetadataIndexer extends BaseMetadataIndexer implements IMetadataIndexer {

@Autowired
private MetadataDraftRepository metadataDraftRepository;

@Override
public void init(ServiceContext context, Boolean force) throws Exception {
super.init(context, force);
metadataDraftRepository = context.getBean(MetadataDraftRepository.class);
}

@Override
/**
* Adds the specific draft related fields.
* @param fullMd
* @param moreFields
*/
protected void addExtraFields(AbstractMetadata fullMd, Vector<Element> moreFields) {
super.addExtraFields(fullMd, moreFields);

if (fullMd instanceof MetadataDraft) {
moreFields.addElement(SearchManager.makeField(Geonet.IndexFieldNames.DRAFT, "Y", true, false));
} else {
if (metadataDraftRepository.exists(fullMd.getId())) {
moreFields.addElement(SearchManager.makeField(Geonet.IndexFieldNames.DRAFT, "E", true, false));
} else {
moreFields.addElement(SearchManager.makeField(Geonet.IndexFieldNames.DRAFT, "N", true, false));
}
}
}
@Autowired
private MetadataDraftRepository metadataDraftRepository;

@Override
public void init(ServiceContext context, Boolean force) throws Exception {
super.init(context, force);
metadataDraftRepository = context.getBean(MetadataDraftRepository.class);
}

@Override
/**
* Adds the specific draft related fields.
*
* @param fullMd
* @param moreFields
*/
protected void addExtraFields(AbstractMetadata fullMd, Vector<Element> moreFields) {
super.addExtraFields(fullMd, moreFields);

if (fullMd instanceof MetadataDraft) {
Log.trace(Geonet.DATA_MANAGER, "We are indexing a draft with uuid " + fullMd.getUuid());
moreFields.addElement(SearchManager.makeField(Geonet.IndexFieldNames.DRAFT, "y", true, true));
} else {
if (metadataDraftRepository.findOneByUuid(fullMd.getUuid()) != null) {
Log.trace(Geonet.DATA_MANAGER,
"We are indexing a record with a draft associated with uuid " + fullMd.getUuid());
moreFields.addElement(SearchManager.makeField(Geonet.IndexFieldNames.DRAFT, "e", true, true));
} else {
Log.trace(Geonet.DATA_MANAGER,
"We are indexing a record with no draft associated with uuid " + fullMd.getUuid());
moreFields.addElement(SearchManager.makeField(Geonet.IndexFieldNames.DRAFT, "n", true, true));
}
}
}
}

0 comments on commit dfa497b

Please sign in to comment.
You can’t perform that action at this time.