Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/maven/fixes/8.1' into maven/rele…
Browse files Browse the repository at this point in the history
…ase/8.1
  • Loading branch information
metaventis-build committed Jun 18, 2024
2 parents c275b94 + 6851cf0 commit 355a5d5
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.edu_sharing.alfresco.policy;

import java.util.Collections;
import java.util.List;
import java.util.Map;

import org.alfresco.repo.copy.CopyServicePolicies;
Expand Down Expand Up @@ -46,6 +48,16 @@ public void beforeCopy(QName qName, NodeRef sourceNode, NodeRef targetNode) {
}
}

public static void removeCopiedUsages(NodeService nodeService, NodeRef targetNodeRef) {
if(!nodeService.getType(targetNodeRef).equals(QName.createQName(CCConstants.CCM_TYPE_IO))) {
return;
}
List<ChildAssociationRef> assocs = nodeService.getChildAssocs(targetNodeRef, Collections.singleton(QName.createQName(CCConstants.CCM_TYPE_USAGE)));
for(ChildAssociationRef assoc: assocs) {
Logger.getLogger(OnCopyIOPolicy.class).debug("Deleting usage: " + assoc.getChildRef() + " from node " + assoc.getParentRef());
nodeService.deleteNode(assoc.getChildRef());
}
}
@Override
public void onCopyComplete(QName classRef, NodeRef sourceNodeRef, NodeRef targetNodeRef, boolean copyToNewNode, Map<NodeRef, NodeRef> copyMap) {
logger.info("will set " + versionProp.toPrefixString() + " to 1.0");
Expand Down Expand Up @@ -77,6 +89,9 @@ public void onCopyComplete(QName classRef, NodeRef sourceNodeRef, NodeRef target
nodeService.removeProperty(targetNodeRef, QName.createQName(CCConstants.CCM_PROP_TRACKING_DOWNLOADS));
nodeService.removeProperty(targetNodeRef, QName.createQName(CCConstants.CCM_PROP_TRACKING_VIEWS));
}

// @TODO: Enable in 9.0!
// removeCopiedUsages(nodeService, targetNodeRef);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ public HandleService() throws HandleServiceNotConfiguredException{
handleServerPrefix = config.getString("prefix");
handleServerRepoId = config.getString("repoid");
privkeyPath = config.getString("privkey");
/**
* config dir: must be writeable
*/
String configDir = (config.hasPath("configDir")) ? config.getString("configDir") : null;
if(configDir != null){
System.setProperty("net.handle.configDir", configDir);
}
id = "0.NA/"+handleServerPrefix;
}else {
throw new HandleServiceNotConfiguredException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static String getPath() {
public static Collection<MetadataWidget> getWidgetsByNode(NodeRef node, String locale) throws Exception {
ApplicationContext alfApplicationContext = AlfAppContextGate.getApplicationContext();
ServiceRegistry serviceRegistry = (ServiceRegistry) alfApplicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
String mdsSet = serviceRegistry.getNodeService().getProperty(node, QName.createQName(CCConstants.CM_PROP_METADATASET_EDU_METADATASET)).toString();
String mdsSet = (String) serviceRegistry.getNodeService().getProperty(node, QName.createQName(CCConstants.CM_PROP_METADATASET_EDU_METADATASET));
if (mdsSet == null || mdsSet.isEmpty()) {
mdsSet = CCConstants.metadatasetdefault_id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.namespace.QName;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.edu_sharing.alfrescocontext.gate.AlfAppContextGate;
import org.edu_sharing.repository.client.tools.CCConstants;
import org.edu_sharing.repository.server.jobs.helper.NodeRunner;
import org.edu_sharing.repository.server.jobs.quartz.annotation.JobDescription;
import org.edu_sharing.repository.server.jobs.quartz.annotation.JobFieldDescription;
import org.edu_sharing.repository.server.tools.ApplicationInfoList;
import org.edu_sharing.restservices.shared.Node;
import org.edu_sharing.service.nodeservice.NodeServiceFactory;
Expand All @@ -52,31 +55,35 @@
import java.util.List;
import java.util.stream.Collectors;

/**
* Remove orphan usages pointing to non-existing collection references
* Required parameters:
* testRun: Only test/output
*/
public class RemoveOrphanCollectionUsageDescriptions extends AbstractJob{
@JobDescription(description = "Remove orphan usages pointing to non-existing collection references")
public class RemoveOrphanCollectionUsageDescriptions extends AbstractJobMapAnnotationParams{
public enum RemoveMode {
@JobFieldDescription(description = "Orphan collection usages, pointing to a non-existing collection reference")
Orphan,
@JobFieldDescription(description = "Usages that are having a wrong parent (probably due to wrongly copied from an other node)")
WrongParent,
}

protected Logger logger = Logger.getLogger(RemoveOrphanCollectionUsageDescriptions.class);
private List<String> types;
@JobFieldDescription(description = "mode to use")
private RemoveMode mode;
@JobFieldDescription(description = "log only?")
private Boolean testRun;
private NodeService nodeService;


@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
public void executeInternal(JobExecutionContext context) throws JobExecutionException {
ApplicationContext applicationContext = AlfAppContextGate.getApplicationContext();

ServiceRegistry serviceRegistry = (ServiceRegistry) applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);

nodeService = serviceRegistry.getNodeService();
org.edu_sharing.service.nodeservice.NodeService nodeServiceEdu = NodeServiceFactory.getLocalService();

Object testRunStr = context.getJobDetail().getJobDataMap().get("testRun");
if(testRunStr==null){
if(testRun==null){
throw new IllegalArgumentException("Missing required boolean parameter 'testRun'");
}
boolean testRun = Boolean.parseBoolean(testRunStr.toString());

String localApp = ApplicationInfoList.getHomeRepository().getAppId();
NodeRunner runner = new NodeRunner();
Expand All @@ -85,15 +92,28 @@ public void execute(JobExecutionContext context) throws JobExecutionException {
logger.info("Node " + ref + " is already deleted, skipping");
return;
}
String appId = (String) NodeServiceHelper.getPropertyNative(ref, CCConstants.CCM_PROP_USAGE_APPID);
if(localApp.equals(appId) || isNodeCollection((String) NodeServiceHelper.getPropertyNative(ref, CCConstants.CCM_PROP_USAGE_COURSEID))){
String refNodeId = NodeServiceHelper.getProperty(ref, CCConstants.CCM_PROP_USAGE_RESSOURCEID);
if(!nodeService.exists(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, refNodeId))) {
logger.info("Delete orphan usage from node: " + nodeService.getPrimaryParent(ref).getParentRef().getId() +
" Target Ref id: " + refNodeId +
" Collection id: " + NodeServiceHelper.getPropertyNative(ref, CCConstants.CCM_PROP_USAGE_COURSEID)
if(mode.equals(RemoveMode.Orphan)) {
String appId = (String) NodeServiceHelper.getPropertyNative(ref, CCConstants.CCM_PROP_USAGE_APPID);
if (localApp.equals(appId) || isNodeCollection((String) NodeServiceHelper.getPropertyNative(ref, CCConstants.CCM_PROP_USAGE_COURSEID))) {
String refNodeId = NodeServiceHelper.getProperty(ref, CCConstants.CCM_PROP_USAGE_RESSOURCEID);
if (!nodeService.exists(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, refNodeId))) {
logger.info("Delete orphan usage from node: " + nodeService.getPrimaryParent(ref).getParentRef().getId() +
" Target Ref id: " + refNodeId +
" Collection id: " + NodeServiceHelper.getPropertyNative(ref, CCConstants.CCM_PROP_USAGE_COURSEID)
);
if (!testRun) {
nodeServiceEdu.removeNode(ref.getId(), null, false);
}
}
}
} else if(mode.equals(RemoveMode.WrongParent)) {
if(!StringUtils.equals((String) NodeServiceHelper.getPropertyNative(ref, CCConstants.CM_NAME), (String) NodeServiceHelper.getPropertyNative(ref, CCConstants.SYS_PROP_NODE_UID))
&& !StringUtils.equals((String) NodeServiceHelper.getPropertyNative(ref, CCConstants.CCM_PROP_USAGE_PARENTNODEID), nodeService.getPrimaryParent(ref).getParentRef().getId())
) {
logger.info("Delete usage with wrong data from node: " + nodeService.getPrimaryParent(ref).getParentRef() +
" Reported parent id: " + NodeServiceHelper.getPropertyNative(ref, CCConstants.CCM_PROP_USAGE_PARENTNODEID)
);
if(!testRun) {
if (!testRun) {
nodeServiceEdu.removeNode(ref.getId(), null, false);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,19 @@ public NodeDao copyProperties(NodeDao fromDao) throws DAOException {
try {
MetadataSet mds = MetadataHelper.getMetadataset(new NodeRef(repoDao, getId()));
HashSet<String> defaultProps = mds.getWidgetsByNode(getType(), getAspectsNative(), false).stream().map(MetadataWidget::getId).collect(Collectors.toCollection(HashSet::new));
defaultProps.addAll(mds.getWidgetsByNode(getType(), getAspectsNative(), false).stream().map(MetadataWidget::getSuggestDisplayProperty).filter(Objects::nonNull).collect(Collectors.toSet()));
defaultProps.addAll(Arrays.stream(NodeCustomizationPolicies.SAFE_PROPS).map(CCConstants::getValidLocalName).collect(Collectors.toList()));
defaultProps.addAll(Arrays.stream(NodeCustomizationPolicies.LICENSE_PROPS).map(CCConstants::getValidLocalName).collect(Collectors.toList()));
for (String prop : defaultProps) {
if (!props.containsKey(prop)) {
if (!props.containsKey(prop) && CCConstants.getValidGlobalName(prop) != null &&
// protected publish props
!Arrays.asList(
CCConstants.CCM_PROP_IO_PUBLISHED_ORIGINAL, CCConstants.CCM_PROP_IO_PUBLISHED_MODE,
CCConstants.CCM_PROP_PUBLISHED_HANDLE_ID, CCConstants.CCM_PROP_IO_PUBLISHED_DATE
).contains(CCConstants.getValidGlobalName(prop))
) {
// delete removed properties
nodeService.removeProperty(getStoreProtocol(), getStoreIdentifier(), getId(), prop);
nodeService.removeProperty(getStoreProtocol(), getStoreIdentifier(), getId(), CCConstants.getValidGlobalName(prop));
}
}
// copy version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.edu_sharing.alfresco.authentication.HttpContext;
import org.edu_sharing.alfresco.lightbend.LightbendConfigLoader;
import org.edu_sharing.alfresco.policy.NodeCustomizationPolicies;
import org.edu_sharing.alfresco.policy.OnCopyIOPolicy;
import org.edu_sharing.alfresco.service.handleservice.HandleService;
import org.edu_sharing.alfresco.tools.EduSharingNodeHelper;
import org.edu_sharing.alfrescocontext.gate.AlfAppContextGate;
Expand Down Expand Up @@ -140,6 +141,7 @@ public NodeRef copyNode(String nodeId, String toNodeId, boolean copyChildren) th
new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, toNodeId),
QName.createQName(CCConstants.CM_ASSOC_FOLDER_CONTAINS),
QName.createQName(originalName), copyChildren);

int renameCounter = 1;
while(true) {
try {
Expand Down Expand Up @@ -1213,6 +1215,7 @@ public String publishCopy(String nodeId, HandleMode handleMode) throws Throwable
NodeRef newNode;
try {
newNode = copyNode(nodeId, container, true);
OnCopyIOPolicy.removeCopiedUsages(nodeService, newNode);
} catch (Throwable t) {
throw new RuntimeException(t);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -946,9 +946,15 @@ export class MdsEditorInstanceService implements OnDestroy {
!widget.definition.values &&
widget.getInitialValues().jointValues
) {
const mdsValueList = await widget.getValuesForKeys(
let mdsValueList = (await widget.getValuesForKeys(
widget.getInitialValues().jointValues,
);
)) || { values: [] };
if (widget.getInitialValues().individualValues) {
mdsValueList.values = mdsValueList.values.concat(
(await widget.getValuesForKeys(widget.getInitialValues().individualValues))
?.values,
);
}
if (mdsValueList) {
widget.setInitialDisplayValues(mdsValueList);
}
Expand Down
2 changes: 2 additions & 0 deletions config/defaults/src/main/resources/edu-sharing.reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ repository: {
privkey: null
repoid: null
email: null
// path to a writeable directory. defaults to $HOME/.handle/
configDir: null
}
register: {
// Class to use, for creating Alfresco Users use "RegisterServiceImpl", for LDAP "RegisterServiceLDAPImpl"
Expand Down

0 comments on commit 355a5d5

Please sign in to comment.