Skip to content

Commit 6c6075d

Browse files
Merge remote-tracking branch 'origin/maven/fixes/9.1' into maven/release/9.1
2 parents 40b2107 + c27f234 commit 6c6075d

File tree

68 files changed

+1125
-218
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1125
-218
lines changed

Backend/alfresco/common/src/main/java/org/edu_sharing/repository/client/tools/CCConstants.java

+1
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,7 @@ public static String getMetadataContributerProp(String role){
12101210

12111211
public final static String CCM_PROP_CCRESSOURCETYPE ="{http://www.campuscontent.de/model/1.0}ccressourcetype";
12121212
public final static String CCM_PROP_CCRESSOURCESUBTYPE ="{http://www.campuscontent.de/model/1.0}ccresourcesubtype";
1213+
public final static String CCM_PROP_CCRESSOURCE_MAIN_ENTITY ="{http://www.campuscontent.de/model/1.0}ccressourcemainentity";
12131214

12141215
public final static String CCM_PROP_CCRESSOURCEVERSION ="{http://www.campuscontent.de/model/1.0}ccressourceversion";
12151216

Backend/alfresco/module/pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@
216216
<dependencies>
217217

218218
<!-- compile -->
219+
<dependency>
220+
<groupId>org.jetbrains</groupId>
221+
<artifactId>annotations</artifactId>
222+
</dependency>
223+
219224
<dependency>
220225
<groupId>org.apache.axis</groupId>
221226
<artifactId>axis</artifactId>

Backend/alfresco/module/src/main/amp/config/alfresco/extension/es_models/ccmodel.xml

+4
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,10 @@
598598
<property name="ccm:ccressourcetype">
599599
<type>d:text</type>
600600
</property>
601+
<!-- the main entity of the resource, i.e. the path to an index.html for web zips or scorm packages -->
602+
<property name="ccm:ccressourcemainentity">
603+
<type>d:text</type>
604+
</property>
601605
<property name="ccm:ccresourcesubtype">
602606
<type>d:text</type>
603607
<multiple>true</multiple>

Backend/alfresco/module/src/main/java/org/edu_sharing/alfresco/action/RessourceInfoExecuter.java

+17-9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.google.gson.Gson;
44
import com.google.gson.JsonSyntaxException;
5+
import lombok.RequiredArgsConstructor;
56
import org.alfresco.model.ContentModel;
67
import org.alfresco.repo.action.executer.ActionExecuterAbstractBase;
78
import org.alfresco.service.cmr.action.Action;
@@ -22,6 +23,8 @@
2223
import org.apache.commons.logging.Log;
2324
import org.apache.commons.logging.LogFactory;
2425
import org.apache.tika.Tika;
26+
import org.edu_sharing.alfresco.lightbend.LightbendConfigLoader;
27+
import org.edu_sharing.repository.client.tools.CCConstants;
2528
import org.w3c.dom.Document;
2629
import org.w3c.dom.Node;
2730
import org.w3c.dom.NodeList;
@@ -34,8 +37,9 @@
3437
import java.util.Arrays;
3538
import java.util.List;
3639

40+
@RequiredArgsConstructor
3741
public class RessourceInfoExecuter extends ActionExecuterAbstractBase {
38-
42+
private final LightbendConfigLoader configLoader;
3943
private static final long MAX_JSON_PARSE_SIZE = 1024 * 1024 * 1;
4044
/** The logger */
4145
private static Log logger = LogFactory.getLog(RessourceInfoExecuter.class);
@@ -66,7 +70,7 @@ public class RessourceInfoExecuter extends ActionExecuterAbstractBase {
6670
public static final String CCM_RESSOURCETYPE_SERLO = "serlo";
6771
public static final String CCM_RESSOURCETYPE_EDUHTML = "eduhtml";
6872

69-
public static ArchiveInputStream getZipInputStream(ContentReader contentreader) throws IOException {
73+
public static ArchiveInputStream getZipInputStream(ContentReader contentreader) throws IOException {
7074
InputStream is = contentreader.getContentInputStream();
7175

7276
Tika tika = new Tika();
@@ -108,7 +112,7 @@ protected void executeImpl(Action action, NodeRef actionedUponNodeRef) {
108112
ArchiveInputStream zip = getZipInputStream(contentreader);
109113
ArchiveEntry current = null;
110114
if(zip!=null) {
111-
boolean genericHtmlFallback = false;
115+
String genericHtmlFile = null;
112116
while ((current = zip.getNextEntry()) != null) {
113117
if (current.getName().equals("imsmanifest.xml")) {
114118

@@ -117,8 +121,8 @@ protected void executeImpl(Action action, NodeRef actionedUponNodeRef) {
117121
return;
118122

119123
}
120-
if (current.getName().equalsIgnoreCase("index.html") || current.getName().equalsIgnoreCase("index.htm")) {
121-
genericHtmlFallback = true;
124+
if (current.getName().matches(configLoader.getConfig().getString("repository.parsers.eduhtml.indexPattern"))) {
125+
genericHtmlFile = current.getName();
122126
}
123127

124128
if (current.getName().equals("moodle.xml")) {
@@ -146,8 +150,8 @@ protected void executeImpl(Action action, NodeRef actionedUponNodeRef) {
146150
}
147151

148152
zip.close();
149-
if(genericHtmlFallback){
150-
proccessGenericHTML(actionedUponNodeRef);
153+
if(genericHtmlFile != null){
154+
proccessGenericHTML(actionedUponNodeRef, genericHtmlFile);
151155
}
152156
} else {
153157
if(Arrays.asList("application/json", "text/plain", "application/octet-stream").contains(contentreader.getMimetype()) &&
@@ -190,12 +194,13 @@ boolean processSerlo(InputStream is, NodeRef nodeRef) {
190194
return false;
191195
}
192196

193-
private void proccessGenericHTML(NodeRef nodeRef) {
197+
private void proccessGenericHTML(NodeRef nodeRef, String genericHtmlFile) {
194198
nodeService.addAspect(nodeRef, QName.createQName(CCM_ASPECT_RESSOURCEINFO),
195199
null);
196200
nodeService.setProperty(nodeRef, QName.createQName(CCM_PROP_IO_RESSOURCETYPE),
197201
CCM_RESSOURCETYPE_EDUHTML);
198-
202+
nodeService.setProperty(nodeRef, QName.createQName(CCConstants.CCM_PROP_CCRESSOURCE_MAIN_ENTITY),
203+
genericHtmlFile);
199204
// check if file contains unity content (web gl)
200205
try{
201206
ContentReader contentreader = this.contentService.getReader(nodeRef, ContentModel.PROP_CONTENT);
@@ -290,6 +295,9 @@ private void process(InputStream is, ContentReader contentreader, NodeRef action
290295
ressourceType);
291296
nodeService.setProperty(actionedUponNodeRef, QName.createQName(CCM_PROP_IO_RESSOURCEVERSION),
292297
ressourceVersion);
298+
299+
String href = "/manifest/resources/resource[position()=1]/@href";
300+
nodeService.setProperty(actionedUponNodeRef, QName.createQName(CCConstants.CCM_PROP_CCRESSOURCE_MAIN_ENTITY), xpath.evaluate(href, doc));
293301
if (isQtiList.size() > 0) {
294302
ArrayList<String> qtiInfoSubtypeList = new ArrayList<>();
295303
for (RessourceInfoTool.QTIInfo qtiInfo : isQtiList) {

Backend/alfresco/module/src/main/java/org/edu_sharing/alfresco/repository/server/authentication/Context.java

+20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.edu_sharing.alfresco.repository.server.authentication;
22

3+
import org.jetbrains.annotations.NotNull;
4+
import org.jetbrains.annotations.Nullable;
35
import jakarta.servlet.ServletContext;
46
import jakarta.servlet.http.HttpServletRequest;
57
import jakarta.servlet.http.HttpServletResponse;
@@ -35,17 +37,23 @@ private Context(HttpServletRequest request, HttpServletResponse response) {
3537
this.response = response;
3638
}
3739

40+
@Nullable
3841
public static Context getCurrentInstance() {
3942
return instance.get();
4043
}
4144

45+
@Nullable
4246
public static ServletContext getGlobalContext() {
4347
return globalContext;
4448
}
49+
50+
@Nullable
4551
public static Context setInstance(Context context){
4652
instance.set(context);
4753
return context;
4854
}
55+
56+
@NotNull
4957
public static Context newInstance(HttpServletRequest request, HttpServletResponse response, ServletContext servletContext) {
5058
Context context = new Context(request,response);
5159
if(globalContext==null)
@@ -124,18 +132,22 @@ public static void release() {
124132
instance.remove();
125133
}
126134

135+
@Nullable
127136
public HttpServletRequest getRequest() {
128137
return request;
129138
}
130139

140+
@Nullable
131141
public B3 getB3() {
132142
return b3;
133143
}
134144

145+
@Nullable
135146
public HttpServletResponse getResponse() {
136147
return response;
137148
}
138149

150+
@Nullable
139151
public String getSessionAttribute(String key){
140152
String sessionAtt = null;
141153
if(this.getRequest() != null
@@ -183,6 +195,7 @@ public synchronized void addSingleUseNode(String nodeId) {
183195
this.getRequest().getSession().setAttribute(CCConstants.AUTH_SINGLE_USE_NODEIDS, list);
184196
}
185197

198+
@Nullable
186199
public String getSessionId(){
187200
if(this.getRequest() != null
188201
&& this.getRequest().getSession() != null){
@@ -191,27 +204,34 @@ public String getSessionId(){
191204
return null;
192205
}
193206

207+
@Nullable
194208
public String getLocale(){
195209
return getSessionAttribute(CCConstants.AUTH_LOCALE);
196210
}
197211

212+
@Nullable
198213
public String getAuthType(){
199214
return getSessionAttribute(CCConstants.AUTH_TYPE);
200215
}
201216

217+
@Nullable
202218
public String getAccessToken(){
203219
return getSessionAttribute(CCConstants.AUTH_ACCESS_TOKEN);
204220
}
205221

206222
public interface B3 {
223+
224+
@Nullable
207225
default String getTraceId() {
208226
return null;
209227
}
210228

229+
@Nullable
211230
default String getClientTraceId() {
212231
return null;
213232
}
214233

234+
@Nullable
215235
default String getSpanId() {
216236
return null;
217237
}

Backend/alfresco/module/src/main/java/org/edu_sharing/metadataset/v2/MetadataReader.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -778,8 +778,8 @@ private List<MetadataKey> getValues(NodeList keysNode, String valuespaceI18n, St
778778
? key.getKey()
779779
: cap,
780780
fallback));
781-
key.setDescription(getTranslation(key, description));
782-
key.setAbbreviation(getTranslation(key, abbreviation));
781+
key.setDescription(getTranslation(key, description, ""));
782+
key.setAbbreviation(getTranslation(key, abbreviation, ""));
783783
keys.add(key);
784784
}
785785
return keys;
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
package org.edu_sharing.repository.tools;
22

33
import jakarta.servlet.http.HttpServletRequest;
4-
import org.apache.commons.logging.Log;
5-
import org.apache.commons.logging.LogFactory;
4+
import lombok.NonNull;
5+
import lombok.extern.slf4j.Slf4j;
6+
import org.apache.commons.lang3.StringUtils;
67
import org.edu_sharing.alfresco.repository.server.authentication.Context;
78
import org.edu_sharing.repository.server.RequestHelper;
89
import org.edu_sharing.repository.server.tools.ApplicationInfo;
910
import org.edu_sharing.repository.server.tools.ApplicationInfoList;
1011

12+
@Slf4j
1113
public class URLHelper {
1214

13-
private static Log logger = LogFactory.getLog(URLHelper.class);
14-
15-
public static String getBaseUrl(boolean dynamic){
15+
public static String getBaseUrl(boolean dynamic) {
1616
ApplicationInfo homeRepository = ApplicationInfoList.getHomeRepository();
17-
if(dynamic && homeRepository.getBoolean(ApplicationInfo.KEY_URL_DYNAMIC,false)) {
17+
if (dynamic && homeRepository.getBoolean(ApplicationInfo.KEY_URL_DYNAMIC, false)) {
1818
try {
1919
HttpServletRequest req = Context.getCurrentInstance().getRequest();
2020
return getBaseUrlFromRequest(req);
21-
}
22-
catch(Throwable t){
23-
logger.debug("Failed to get dynamic base url, will use the one defined in homeApp");
21+
} catch (Throwable t) {
22+
log.debug("Failed to get dynamic base url, will use the one defined in homeApp");
2423
}
2524
}
2625

@@ -48,46 +47,72 @@ public static String getNgRenderNodeUrl(String nodeId, String version, boolean d
4847

4948
/**
5049
* Get the url to the angular rendering component
50+
*
5151
* @param nodeId
5252
* @param version may be null to use the latest
5353
* @return
5454
*/
55-
public static String getNgRenderNodeUrl(String nodeId,String version,boolean dynamic, String repository) {
56-
String ngComponentsUrl = getNgComponentsUrl(dynamic)+"render/"+nodeId+(version!=null && !version.equals("-1") && !version.trim().isEmpty() ? "/"+version : "");
57-
if(repository != null) {
58-
ngComponentsUrl+="?repository="+repository;
55+
public static String getNgRenderNodeUrl(String nodeId, String version, boolean dynamic, String repository) {
56+
return getNgRenderNodeUrl(getNgComponentsUrl(dynamic), nodeId, version, repository);
57+
}
58+
59+
public static String getNgRenderNodeUrl(String domain, String nodeId, String version) {
60+
return getNgRenderNodeUrl(getNgComponentsUrl(domain), nodeId, version, null);
61+
}
62+
63+
private static String getNgRenderNodeUrl(@NonNull String domain, @NonNull String nodeId, String version, String repository) {
64+
StringBuilder sb = new StringBuilder(2048);
65+
sb.append(domain);
66+
sb.append("render/");
67+
sb.append(nodeId);
68+
69+
if(StringUtils.isNotBlank(version) && !version.equals("-1")) {
70+
sb.append("/");
71+
sb.append(version);
5972
}
60-
return ngComponentsUrl;
73+
74+
if (StringUtils.isNotBlank(repository)) {
75+
sb.append("?repository=");
76+
sb.append(repository);
77+
}
78+
79+
return sb.toString();
6180
}
6281

63-
public static String getBaseUrl(String repositoryId){
82+
83+
public static String getBaseUrl(String repositoryId) {
6484
ApplicationInfo repository = ApplicationInfoList.getRepositoryInfoById(repositoryId);
65-
String hostOrDomain = (repository.getDomain() == null || repository.getDomain().trim().equals(""))? repository.getHost() : repository.getDomain();
6685

67-
String host = hostOrDomain;
68-
logger.debug("host:"+host);
86+
String host = StringUtils.isBlank(repository.getDomain())
87+
? repository.getHost()
88+
: repository.getDomain();
89+
log.debug("host:{}", host);
6990
String port = repository.getClientport();
70-
logger.debug("port:"+port);
91+
log.debug("port:{}", port);
7192
String edusharingcontext = repository.getWebappname();
72-
logger.debug("edusharingcontext:"+edusharingcontext);
93+
log.debug("edusharingcontext:{}", edusharingcontext);
7394

7495
String protocol = repository.getClientprotocol();
7596

7697

77-
String baseUrl = null;
78-
if(port.equals("80") || port.equals("443")){
79-
baseUrl = protocol+"://" + host + "/"+edusharingcontext;
80-
}else{
81-
baseUrl = protocol+"://" + host + ":" + port + "/"+ edusharingcontext;
98+
String baseUrl;
99+
if (port.equals("80") || port.equals("443")) {
100+
baseUrl = protocol + "://" + host + "/" + edusharingcontext;
101+
} else {
102+
baseUrl = protocol + "://" + host + ":" + port + "/" + edusharingcontext;
82103
}
83104
return baseUrl;
84105
}
85106

86-
public static String getNgComponentsUrl(){
107+
public static String getNgComponentsUrl() {
87108
return getNgComponentsUrl(true);
88109
}
89110

90-
public static String getNgComponentsUrl(boolean dynamic){
91-
return getBaseUrl(dynamic)+"/components/";
111+
public static String getNgComponentsUrl(String baseUrl) {
112+
return baseUrl.replaceAll("/$","") + "/components/";
113+
}
114+
115+
public static String getNgComponentsUrl(boolean dynamic) {
116+
return getNgComponentsUrl(getBaseUrl(dynamic));
92117
}
93118
}

Backend/alfresco/module/src/test/java/org/edu_sharing/alfresco/action/RessourceInfoExecuterTest.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import org.alfresco.service.cmr.repository.NodeService;
88
import org.alfresco.service.cmr.repository.StoreRef;
99
import org.alfresco.service.namespace.QName;
10+
import org.edu_sharing.alfresco.lightbend.LightbendConfigCache;
11+
import org.edu_sharing.alfresco.lightbend.LightbendConfigLoader;
1012
import org.junit.jupiter.api.Assertions;
1113
import org.junit.jupiter.api.BeforeEach;
1214
import org.junit.jupiter.api.Test;
@@ -23,9 +25,10 @@ class RessourceInfoExecuterTest {
2325
private RessourceInfoExecuter underTest;
2426

2527
private final NodeService mockedNodeService = Mockito.mock(NodeService.class);
28+
private final LightbendConfigLoader mockedLightbendConfigLoader = Mockito.mock(LightbendConfigLoader.class);
2629
@BeforeEach
2730
void setUp() {
28-
underTest = new RessourceInfoExecuter();
31+
underTest = new RessourceInfoExecuter(mockedLightbendConfigLoader);
2932
underTest.setNodeService(mockedNodeService);
3033
}
3134

0 commit comments

Comments
 (0)