Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/maven/fixes/9.1' into maven/rele…
Browse files Browse the repository at this point in the history
…ase/9.1
  • Loading branch information
metaventis-build committed Nov 8, 2024
2 parents e01e766 + 5005193 commit edc895e
Show file tree
Hide file tree
Showing 21 changed files with 322 additions and 189 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,36 +131,11 @@ public class NodeCustomizationPolicies implements OnContentUpdatePolicy, OnCreat
CCConstants.CCM_PROP_RESTRICTED_ACCESS,
CCConstants.CCM_PROP_RESTRICTED_ACCESS_PERMISSIONS,
};
/**
* These are the properties that will be copied to all io_reference nodes inside collections
* if the original node gets changed
*/
private static final Collection<String> IO_REFERENCE_COPY_PROPERTIES = new ArrayList<>(
Arrays.asList(
CCConstants.CCM_PROP_IO_COMMONLICENSE_KEY,
CCConstants.CCM_PROP_IO_COMMONLICENSE_CC_LOCALE,
CCConstants.CCM_PROP_IO_COMMONLICENSE_CC_VERSION,
CCConstants.CCM_PROP_IO_COMMONLICENSE_QUESTIONSALLOWED,
CCConstants.CCM_PROP_IO_LICENSE,
CCConstants.CCM_PROP_IO_LICENSE_DESCRIPTION,
CCConstants.CCM_PROP_IO_LICENSE_FROM,
CCConstants.CCM_PROP_IO_LICENSE_PROFILE_URL,
CCConstants.CCM_PROP_IO_LICENSE_SOURCE_URL,
CCConstants.CCM_PROP_IO_LICENSE_TITLE_OF_WORK,
CCConstants.CCM_PROP_IO_LICENSE_TO,
CCConstants.CCM_PROP_IO_LICENSE_VALID,

// fix for 4.2, override changed content resource props
CCConstants.CCM_PROP_CCRESSOURCETYPE,
CCConstants.CCM_PROP_CCRESSOURCESUBTYPE,
CCConstants.CCM_PROP_CCRESSOURCEVERSION,

// fix for 4.2, override all relevant metadata when changed on original
CCConstants.LOM_PROP_GENERAL_TITLE,
CCConstants.LOM_PROP_GENERAL_KEYWORD,
CCConstants.LOM_PROP_GENERAL_DESCRIPTION,
CCConstants.LOM_PROP_EDUCATIONAL_LEARNINGRESOURCETYPE
)


/* These props are always overriden on a given io reference if the original changes, regardless of the current state */
public static final List<String> IO_REFERENCE_OVERRIDE_PROPS = List.of(
CCConstants.LOM_PROP_TECHNICAL_SIZE
);

public static final String[] LICENSE_PROPS = new String[]{
Expand All @@ -174,12 +149,6 @@ public class NodeCustomizationPolicies implements OnContentUpdatePolicy, OnCreat
CCConstants.CCM_PROP_IO_COMMONLICENSE_QUESTIONSALLOWED
};

static {
// add all contributor array maps (e.g. author) to be copied to collection refs
IO_REFERENCE_COPY_PROPERTIES.addAll(CCConstants.getLifecycleContributerPropsMap().values());
IO_REFERENCE_COPY_PROPERTIES.addAll(CCConstants.getMetadataContributerPropsMap().values());
}


static Logger logger = Logger.getLogger(NodeCustomizationPolicies.class);

Expand Down Expand Up @@ -704,6 +673,14 @@ public static void syncCollectionRefProps(NodeRef nodeRef, NodeRef ref, Map<QNam
}
}
}

// override all specific props
for (QName prop : propSet) {
if (IO_REFERENCE_OVERRIDE_PROPS.contains(prop.toString())) {
ioColRefProperties.put(prop, after.get(prop));
}
}

try {
nodeService.setProperties(ref, ioColRefProperties);
} catch (DuplicateChildNodeNameException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.io.FileNotFoundException;
import java.io.Serializable;
import java.lang.reflect.UndeclaredThrowableException;
import java.nio.file.NoSuchFileException;
import java.security.InvalidKeyException;

import java.lang.reflect.UndeclaredThrowableException;
Expand Down Expand Up @@ -142,6 +143,7 @@ public static DAOException mapping(Throwable t,String nodeId) {
if ( t instanceof NoSuchPersonException
|| t instanceof InvalidStoreRefException
|| t instanceof FileNotFoundException
|| t instanceof NoSuchFileException
|| t instanceof InvalidNodeRefException) {

return new DAOMissingException(t,nodeId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public Response searchUser(
global==null ? true : global,
skipCount!=null ? skipCount : 0,
maxItems!=null ? maxItems : RestConstants.DEFAULT_MAX_ITEMS,
new SortDefinition(CCConstants.NAMESPACE_CM,sortProperties,sortAscending),
new SortDefinition(sortProperties,sortAscending),
filter
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import lombok.RequiredArgsConstructor;
import org.alfresco.repo.cache.SimpleCache;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.module.ModuleInstallState;
import org.alfresco.service.cmr.module.ModuleService;
import org.alfresco.service.cmr.repository.NodeRef;
Expand Down Expand Up @@ -68,6 +69,7 @@
import org.edu_sharing.spring.ApplicationContextFactory;
import org.edu_sharing.spring.scope.refresh.ContextRefreshUtils;
import org.jetbrains.annotations.NotNull;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import org.springframework.util.StreamUtils;
import org.w3c.dom.Document;
Expand Down Expand Up @@ -98,6 +100,8 @@ public class AdminServiceImpl implements AdminService {

private final ModuleService moduleService;
private final VersionService versionService;
private final ApplicationContext applicationContext = AlfAppContextGate.getApplicationContext();
private final ServiceRegistry serviceRegistry = (ServiceRegistry) applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);

//cause standard properties class does not save the values sorted
static class SortedProperties extends Properties {
Expand Down Expand Up @@ -172,44 +176,47 @@ public Map<String, ToolPermission> getToolpermissions(String authority) throws T
if (!isEveryone && AuthorityServiceFactory.getLocalService().getMemberships(authority).contains(CCConstants.AUTHORITY_GROUP_ALFRESCO_ADMINISTRATORS)) {
throw new IllegalArgumentException("Toolpermissions are not supported for members of " + CCConstants.AUTHORITY_GROUP_ALFRESCO_ADMINISTRATORS);
}
Map<String, ToolPermission> toolpermissions = new HashMap<>();
// refresh the tp in this case, since may a new one is created meanwhile by the client
for (String tp : tpService.getAllToolPermissions(true)) {
String nodeId = tpService.getToolPermissionNodeId(tp, true);
List<String> permissionsExplicit = permissionService.getExplicitPermissionsForAuthority(nodeId, authority);
List<String> permissions = permissionService.getPermissionsForAuthority(nodeId, authority);
ToolPermission status = new ToolPermission();
Boolean managed = (Boolean) NodeServiceHelper.getPropertyNative(
new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, nodeId),
CCConstants.CCM_PROP_TOOLPERMISSION_SYSTEM_MANAGED
);
status.setSystemManaged(managed != null && managed);

if (permissionsExplicit.contains(CCConstants.PERMISSION_DENY)) {
status.setExplicit(ToolPermission.Status.DENIED);
} else if (permissionsExplicit.contains(CCConstants.PERMISSION_READ)) {
status.setExplicit(ToolPermission.Status.ALLOWED);
}
if (permissions.contains(CCConstants.PERMISSION_DENY)) {
status.setEffective(ToolPermission.Status.DENIED);
status.setEffectiveSource(getEffectiveSource(nodeId, authority, CCConstants.PERMISSION_DENY));
} else if (permissions.contains(CCConstants.PERMISSION_READ)) {
status.setEffective(ToolPermission.Status.ALLOWED);
status.setEffectiveSource(getEffectiveSource(nodeId, authority, CCConstants.PERMISSION_READ));
// transaction reduces additional sub-transactions and improves performance significantly
return serviceRegistry.getRetryingTransactionHelper().doInTransaction(() -> {
Map<String, ToolPermission> toolpermissions = new HashMap<>();
// refresh the tp in this case, since may a new one is created meanwhile by the client
for (String tp : tpService.getAllToolPermissions(true)) {
String nodeId = tpService.getToolPermissionNodeId(tp, true);
List<String> permissionsExplicit = permissionService.getExplicitPermissionsForAuthority(nodeId, authority);
List<String> permissions = permissionService.getPermissionsForAuthority(nodeId, authority);
ToolPermission status = new ToolPermission();
Boolean managed = (Boolean) NodeServiceHelper.getPropertyNative(
new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, nodeId),
CCConstants.CCM_PROP_TOOLPERMISSION_SYSTEM_MANAGED
);
status.setSystemManaged(managed != null && managed);

if (permissionsExplicit.contains(CCConstants.PERMISSION_DENY)) {
status.setExplicit(ToolPermission.Status.DENIED);
} else if (permissionsExplicit.contains(CCConstants.PERMISSION_READ)) {
status.setExplicit(ToolPermission.Status.ALLOWED);
}
if (permissions.contains(CCConstants.PERMISSION_DENY)) {
status.setEffective(ToolPermission.Status.DENIED);
status.setEffectiveSource(getEffectiveSource(nodeId, authority, CCConstants.PERMISSION_DENY));
} else if (permissions.contains(CCConstants.PERMISSION_READ)) {
status.setEffective(ToolPermission.Status.ALLOWED);
status.setEffectiveSource(getEffectiveSource(nodeId, authority, CCConstants.PERMISSION_READ));
}
toolpermissions.put(tp, status);
}
toolpermissions.put(tp, status);
}
return toolpermissions;
return toolpermissions;
});
}

private List<Group> getEffectiveSource(String nodeId, String authority, String permissionName) throws Exception {
PermissionService permissionService = PermissionServiceFactory.getLocalService();
List<Group> result = new ArrayList<>();
// getMemberships can not be called for group everyone
if(authority.equals(CCConstants.AUTHORITY_GROUP_EVERYONE)) {
result.add(Group.getEveryone());
return result;
}
// getMemberships can not be called for group everyone
if(authority.equals(CCConstants.AUTHORITY_GROUP_EVERYONE)) {
result.add(Group.getEveryone());
return result;
}
for (String group : AuthorityServiceFactory.getLocalService().getMemberships(authority)) {
List<String> permissionsExplicit = permissionService.getExplicitPermissionsForAuthority(nodeId, group);
if (permissionsExplicit.contains(permissionName)) {
Expand Down Expand Up @@ -277,29 +284,29 @@ public void setToolpermissions(String authority, Map<String, ToolPermission.Stat
}
}

@Override
public void writePublisherToMDSXml(String vcardProps, String valueSpaceProp, String ignoreValues, String filePath, Map<String,String> authInfo) throws Throwable {
File file = new File(filePath);
Result result = new StreamResult(file);
writePublisherToMDSXml(result,vcardProps,valueSpaceProp,ignoreValues,authInfo);
}
public String getPublisherToMDSXml(List<String> vcardProps, String valueSpaceProp, String ignoreValues, Map<String,String> authInfo) throws Throwable {
StringWriter writer=new StringWriter();
Result result = new StreamResult(writer);
writePublisherToMDSXml(result,StringUtils.join(vcardProps,","),valueSpaceProp,ignoreValues,authInfo);
return writer.toString();
}
@Override
public List<JobInfo> getJobs() throws Throwable {
return JobHandler.getInstance().getAllRunningJobs();
}
@Override
public void cancelJob(String jobName, boolean force) throws Throwable {
if(!JobHandler.getInstance().cancelJob(jobName, force)){
throw new Exception("Job could not be canceled. Scheduler returned false");
}
}
@Override
public void writePublisherToMDSXml(String vcardProps, String valueSpaceProp, String ignoreValues, String filePath, Map<String,String> authInfo) throws Throwable {
File file = new File(filePath);
Result result = new StreamResult(file);
writePublisherToMDSXml(result,vcardProps,valueSpaceProp,ignoreValues,authInfo);
}

public String getPublisherToMDSXml(List<String> vcardProps, String valueSpaceProp, String ignoreValues, Map<String,String> authInfo) throws Throwable {
StringWriter writer=new StringWriter();
Result result = new StreamResult(writer);
writePublisherToMDSXml(result,StringUtils.join(vcardProps,","),valueSpaceProp,ignoreValues,authInfo);
return writer.toString();
}
@Override
public List<JobInfo> getJobs() throws Throwable {
return JobHandler.getInstance().getAllRunningJobs();
}
@Override
public void cancelJob(String jobName, boolean force) throws Throwable {
if(!JobHandler.getInstance().cancelJob(jobName, force)){
throw new Exception("Job could not be canceled. Scheduler returned false");
}
}

public void writePropertyToMDSXml(Result result, String property) throws Throwable {
Collection<String> values = getAllValuesFor(property);
Expand Down Expand Up @@ -555,22 +562,22 @@ private Map<String, String> storeProperties(String appId, Properties props) thro
if (!appFile.exists()) {
props.storeToXML(new FileOutputStream(appFile), "");
} else {
throw new Exception("File "+appFile.getPath() + " already exists");
throw new Exception("File "+appFile.getPath() + " already exists");
}


String existingFileList = getAppPropertiesApplications();
String existingFileList = getAppPropertiesApplications();

if(existingFileList == null) {
try {
boolean ignored = appFile.delete();
} catch(Throwable t){
logger.warn("Could not rollback app file " + appFile.getName(), t);
}
throw new Exception("AppList is currently empty. Please try again later");
}
if(existingFileList == null) {
try {
boolean ignored = appFile.delete();
} catch(Throwable t){
logger.warn("Could not rollback app file " + appFile.getName(), t);
}
throw new Exception("AppList is currently empty. Please try again later");
}

String newProperty=existingFileList+","+filename;
String newProperty=existingFileList+","+filename;
changeAppPropertiesApplications(newProperty, new Date() + " added file:" + filename);


Expand Down Expand Up @@ -946,24 +953,24 @@ public ImmediateJobListener startJob(String jobClass, Map<String, Object> params

}

@Override
public Object startJobSync(String jobClass, Map<String,Object> params) throws Throwable {
ImmediateJobListener listener = startJob(jobClass, params);
while(true) {
if(listener.wasExecuted()) {
Optional<JobInfo> result = getJobs().stream().filter(job -> job.getStatus().equals(JobInfo.Status.Finished) && job.getJobClass().getName().equals(jobClass)).max((a, b) -> Long.compare(a.getFinishTime(), b.getFinishTime()));
if(result.isEmpty()) {
throw new IllegalStateException("Job status not found");
}
return result.get().getJobDataMap().get(JobHandler.KEY_RESULT_DATA);
}
if(listener.isVetoed()) {
throw new Exception("job was vetoed by " + listener.getVetoBy());
}
@Override
public Object startJobSync(String jobClass, Map<String,Object> params) throws Throwable {
ImmediateJobListener listener = startJob(jobClass, params);
while(true) {
if(listener.wasExecuted()) {
Optional<JobInfo> result = getJobs().stream().filter(job -> job.getStatus().equals(JobInfo.Status.Finished) && job.getJobClass().getName().equals(jobClass)).max((a, b) -> Long.compare(a.getFinishTime(), b.getFinishTime()));
if(result.isEmpty()) {
throw new IllegalStateException("Job status not found");
}
return result.get().getJobDataMap().get(JobHandler.KEY_RESULT_DATA);
}
if(listener.isVetoed()) {
throw new Exception("job was vetoed by " + listener.getVetoBy());
}
//noinspection BusyWait
Thread.sleep(1000);
}
}
}
}

@Override
public void startCacheRefreshingJob(String folderId, boolean sticky) throws Exception {
Expand Down Expand Up @@ -1065,16 +1072,16 @@ public List<JobDescription> getJobDescriptions(boolean fetchAbstractJobs) {
JobDescription.JobFieldDescription fieldDesc = new JobDescription.JobFieldDescription();
fieldDesc.setName(f.getName());
boolean isArray = f.getType().isAssignableFrom(Collection.class) || f.getType().equals(List.class);
Class<?> type;
if(isArray) {
Type subtype = ((ParameterizedType) f.getGenericType()).getActualTypeArguments()[0];
if (subtype instanceof ParameterizedType) {
subtype = ((ParameterizedType) subtype).getActualTypeArguments()[0];
}
type = (Class<?>) subtype;
} else {
type = f.getType();
}
Class<?> type;
if(isArray) {
Type subtype = ((ParameterizedType) f.getGenericType()).getActualTypeArguments()[0];
if (subtype instanceof ParameterizedType) {
subtype = ((ParameterizedType) subtype).getActualTypeArguments()[0];
}
type = (Class<?>) subtype;
} else {
type = f.getType();
}
fieldDesc.setType(type);
fieldDesc.setIsArray(isArray);
fieldDesc.setDescription(f.getAnnotation(JobFieldDescription.class).description());
Expand Down
Loading

0 comments on commit edc895e

Please sign in to comment.