Skip to content
Permalink
Browse files

Sharing / Add definition of publish. (#4405)

* Sharing / Add definition of publish.

* Update config-spring-geonetwork.xml
  • Loading branch information
fxprunayre committed Feb 12, 2020
1 parent eb07edf commit 499ff59963f5849f3ac7435de29d0cc374981f3e
@@ -31,7 +31,9 @@
import static org.springframework.data.jpa.domain.Specifications.where;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -85,9 +87,10 @@
import org.fao.geonet.repository.UserGroupRepository;
import org.fao.geonet.repository.UserRepository;
import org.fao.geonet.repository.specification.MetadataValidationSpecs;
import org.fao.geonet.repository.specification.OperationAllowedSpecs;
import org.fao.geonet.repository.specification.UserGroupSpecs;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.domain.Specifications;
@@ -130,7 +133,7 @@

@Autowired
LanguageUtils languageUtils;

@Autowired
DataManager dataManager;

@@ -169,7 +172,14 @@

@Autowired
UserGroupRepository userGroupRepository;


/**
* What does publish mean?
*/
@Autowired
@Qualifier("publicationConfig")
private Map publicationConfig;

@ApiOperation(
value = "Set privileges for ALL group to publish the metadata for all users.",
nickname = "publish")
@@ -328,7 +338,7 @@ MetadataProcessingReport publish(
)
throws Exception {

SharingParameter sharing = buildSharingForAllGroup(true);
SharingParameter sharing = buildSharingForPublicationConfig(true);
return shareSelection(uuids, bucket, sharing, session, request);
}

@@ -362,7 +372,7 @@ MetadataProcessingReport unpublish(
)
throws Exception {

SharingParameter sharing = buildSharingForAllGroup(false);
SharingParameter sharing = buildSharingForPublicationConfig(false);
return shareSelection(uuids, bucket, sharing, session, request);
}

@@ -543,8 +553,8 @@ SharingResponse getRecordSharingSettings(

//--- get all operations that this group can do on given metadata
Specifications<OperationAllowed> hasGroupIdAndMetadataId =
where(OperationAllowedSpecs.hasGroupId(g.getId()))
.and(OperationAllowedSpecs.hasMetadataId(metadata.getId()));
where(hasGroupId(g.getId()))
.and(hasMetadataId(metadata.getId()));
List<OperationAllowed> operationAllowedForGroup =
operationAllowedRepository.findAll(hasGroupIdAndMetadataId);

@@ -730,8 +740,8 @@ MetadataProcessingReport setGroupAndOwner(
required = true
)
Integer userIdentifier,
@ApiParam(value = "Use approved version or not", example = "true")
@RequestParam(required = false, defaultValue = "false")
@ApiParam(value = "Use approved version or not", example = "true")
@RequestParam(required = false, defaultValue = "false")
Boolean approved,
@ApiIgnore
@ApiParam(hidden = true)
@@ -806,8 +816,8 @@ MetadataProcessingReport setRecordOwnership(
required = true
)
Integer userIdentifier,
@ApiParam(value = "Use approved version or not", example = "true")
@RequestParam(required = false, defaultValue = "true")
@ApiParam(value = "Use approved version or not", example = "true")
@RequestParam(required = false, defaultValue = "true")
Boolean approved,
@ApiIgnore
@ApiParam(hidden = true)
@@ -848,7 +858,7 @@ private void updateOwnership(Integer groupIdentifier,
AccessManager accessMan,
MetadataRepository metadataRepository,
ServiceContext serviceContext,
List<String> listOfUpdatedRecords, String uuid,
List<String> listOfUpdatedRecords, String uuid,
HttpSession session, Boolean approved) throws Exception {
AbstractMetadata metadata = metadataUtils.findOneByUuid(uuid);
if (metadata == null) {
@@ -891,7 +901,7 @@ private void updateOwnership(Integer groupIdentifier,
priv.getOperationId());
}
}

Long metadataId = Long.parseLong(ApiUtils.getInternalId(uuid, approved));
ApplicationContext context = ApplicationContextHolder.get();
if(!Objects.equals(groupIdentifier, sourceGrp)) {
@@ -906,7 +916,7 @@ private void updateOwnership(Integer groupIdentifier,
User newOwner = userRepository.findOne(userIdentifier);
User oldOwner = userRepository.findOne(sourceUsr);
new RecordOwnerChangeEvent(metadataId, ApiUtils.getUserSession(session).getUserIdAsInt(), ObjectJSONUtils.convertObjectInJsonObject(oldOwner, RecordOwnerChangeEvent.FIELD), ObjectJSONUtils.convertObjectInJsonObject(newOwner, RecordOwnerChangeEvent.FIELD)).publish(context);
}
}
// -- set the new owner into the metadata record
dataManager.updateMetadataOwner(metadata.getId(),
String.valueOf(userIdentifier),
@@ -989,7 +999,7 @@ private void checkCanPublishToAllGroup(ServiceContext context, DataManager dm, A


/**
* Shares a metadata with the {@link ReservedGroup#all} group to publish/unpublish it.
* Shares a metadata based on the publicationConfig to publish/unpublish it.
*
* @param metadataUuid Metadata uuid.
* @param publish Flag to publish/unpublish the metadata.
@@ -1022,7 +1032,7 @@ private void shareMetadataWithAllGroup(String metadataUuid, boolean publish,
operationMap.put(o.getName(), o.getId());
}

SharingParameter sharing = buildSharingForAllGroup(publish);
SharingParameter sharing = buildSharingForPublicationConfig(publish);

List<GroupOperations> privileges = sharing.getPrivileges();
setOperations(sharing, dataManager, context, appContext, metadata, operationMap, privileges,
@@ -1114,26 +1124,36 @@ private MetadataProcessingReport shareSelection(String[] uuids, String bucket, S
* @param publish Flag to add/remove sharing privileges.
* @return
*/
private SharingParameter buildSharingForAllGroup(boolean publish) {
private SharingParameter buildSharingForPublicationConfig(boolean publish) {
SharingParameter sharing = new SharingParameter();
sharing.setClear(false);

List<GroupOperations> privilegesList = new ArrayList<>();
GroupOperations privAllGroup = new GroupOperations();
privAllGroup.setGroup(ReservedGroup.all.getId());

Map<String, Boolean> operations = new HashMap<>();
operations.put(ReservedOperation.view.name(), publish);
operations.put(ReservedOperation.download.name(), publish);
operations.put(ReservedOperation.dynamic.name(), publish);
final Iterator iterator = publicationConfig.entrySet().iterator();
while(iterator.hasNext()) {
Map.Entry<String, Object[]> e = (Map.Entry<String, Object[]>) iterator.next();
GroupOperations privAllGroup = new GroupOperations();
privAllGroup.setGroup(Integer.parseInt(e.getKey()));

Map<String, Boolean> operations = new HashMap<>();
for (Object operation : e.getValue()) {
operations.put((String)operation, publish);
}

privAllGroup.setOperations(operations);
privilegesList.add(privAllGroup);
privAllGroup.setOperations(operations);
privilegesList.add(privAllGroup);
};

sharing.setPrivileges(privilegesList);

return sharing;
}

public void setPublicationConfig(Map publicationConfig) {
this.publicationConfig = publicationConfig;
}

public Map getPublicationConfig() {
return publicationConfig;
}
}
@@ -22,14 +22,13 @@
~ Rome - Italy. email: geonetwork@osgeo.org
-->

<beans xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<beans xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
default-lazy-init="true"
xmlns="http://www.springframework.org/schema/beans" xsi:schemaLocation="
http://www.springframework.org/schema/beans
xmlns="http://www.springframework.org/schema/beans" xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
">
http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

<context:property-placeholder location="${app.properties}"
file-encoding="UTF-8"
@@ -48,6 +47,33 @@
<constructor-arg index="1" ref="defaultLanguage"/>
</bean>

<!--
Configure here what the publish/unpublish action does.
By default, it set view, download and dynamic operation
to Internet and Intranet group.
-->
<util:map id="publicationConfig"
key-type="java.lang.String"
value-type="java.lang.String[]">
<!-- INTERNET GROUP -->
<entry key="1">
<array>
<!-- View, download, dynamic -->
<value>view</value>
<value>download</value>
<value>dynamic</value>
</array>
</entry>
<!-- INTRANET GROUP -->
<entry key="0">
<array>
<value>view</value>
<value>download</value>
<value>dynamic</value>
</array>
</entry>
</util:map>

<bean id="RegionsDAO" class="org.fao.geonet.services.region.ThesaurusBasedRegionsDAO">
<constructor-arg ref="languages"/>
<property name="cacheAllRegionsInMemory" value="true"/>

0 comments on commit 499ff59

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