Skip to content
Snippets Groups Projects
Commit f88a1f38 authored by Moritzjenny's avatar Moritzjenny
Browse files

Merge branch 'OpenOLAT_15.1'

parents a3e41ce2 c7d4aa9f
No related branches found
No related tags found
No related merge requests found
/**
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at the
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Initial code contributed and copyrighted by<br>
* frentix GmbH, http://www.frentix.com
* <p>
*/
package org.olat.core.commons.services.doceditor.restapi;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.olat.core.CoreSpringFactory;
import org.olat.core.commons.services.doceditor.DocEditor.Mode;
import org.olat.core.commons.services.doceditor.wopi.WopiService;
import org.springframework.stereotype.Component;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
/**
* Description:<br>
* This serves information about the document editors.
*
* Initial date: 09 Jul. 2020<br>
* @author morjen, moritz.jenny@frentix.com, http://www.frentix.com
*
*/
@Component
public class DocEditorSessionWebService {
@GET
@Path("{app}")
@Operation(summary = "Returns information about doceditor", description = "Returns information about the doceditor given as parameter")
@ApiResponse(responseCode = "200", description = "Information about the doceditor", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = DocEditorStatisticsVO.class)),
@Content(mediaType = "application/xml", schema = @Schema(implementation = DocEditorStatisticsVO.class)) })
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public Response getStatistics(@PathParam("app") String app) {
DocEditorStatisticsVO stats = getDocEditorStatistics(app);
return Response.ok(stats).build();
}
private DocEditorStatisticsVO getDocEditorStatistics(String app) {
DocEditorStatisticsVO stats = new DocEditorStatisticsVO();
WopiService wopiService = CoreSpringFactory.getImpl(WopiService.class);
stats.setAppName(app);
stats.setOpenDocumentsWrite(wopiService.getAccessCount(app, Mode.EDIT));
stats.setOpenDocumentsRead(wopiService.getAccessCount(app, Mode.VIEW));
return stats;
}
}
/**
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at the
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Initial code contributed and copyrighted by<br>
* frentix GmbH, http://www.frentix.com
* <p>
*/
package org.olat.core.commons.services.doceditor.restapi;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
/**
* Description:<br>
* This VO holds statistics about a doceditor.
*
* Initial date: 13 Jul. 2020<br>
* @author morjen, moritz.jenny@frentix.com, http://www.frentix.com
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "DocEditorStatisticsVO")
public class DocEditorStatisticsVO {
@XmlAttribute(name="appName", required=false)
private String appName;
@XmlAttribute(name="openDocumentsRead", required=false)
private long openDocumentsRead;
@XmlAttribute(name="openDocumentsWrite", required=false)
private long openDocumentsWrite;
public String getAppName() {
return appName;
}
public void setAppName(String appName) {
this.appName = appName;
}
public long getOpenDocumentsRead() {
return openDocumentsRead;
}
public void setOpenDocumentsRead(long openDocumentsRead) {
this.openDocumentsRead = openDocumentsRead;
}
public long getOpenDocumentsWrite() {
return openDocumentsWrite;
}
public void setOpenDocumentsWrite(long openDocumentsWrite) {
this.openDocumentsWrite = openDocumentsWrite;
}
}
/**
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at the
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Initial code contributed and copyrighted by<br>
* frentix GmbH, http://www.frentix.com
* <p>
*/
package org.olat.core.commons.services.doceditor.restapi;
import javax.ws.rs.Path;
import org.springframework.stereotype.Component;
import io.swagger.v3.oas.annotations.tags.Tag;
/**
* Description:<br>
* This serves information about the document editors.
*
* Initial date: 09 Jul. 2020<br>
* @author morjen, moritz.jenny@frentix.com, http://www.frentix.com
*
*/
@Tag(name = "Document Editor")
@Path("doceditor")
@Component
public class DocEditorWebService {
private static final DocEditorSessionWebService docEditorSessionWebService = new DocEditorSessionWebService();
@Path("sessions")
public DocEditorSessionWebService getStatus() {
return docEditorSessionWebService;
}
}
/**
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at the
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Initial code contributed and copyrighted by<br>
* frentix GmbH, http://www.frentix.com
* <p>
*/
package org.olat.restapi;
import static org.olat.test.JunitTestHelper.random;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Date;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriBuilder;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.junit.Assert;
import org.junit.Test;
import org.olat.core.commons.persistence.DB;
import org.olat.core.commons.services.doceditor.DocEditor.Mode;
import org.olat.core.commons.services.doceditor.DocEditorSecurityCallback;
import org.olat.core.commons.services.doceditor.DocEditorSecurityCallbackBuilder;
import org.olat.core.commons.services.doceditor.restapi.DocEditorStatisticsVO;
import org.olat.core.commons.services.doceditor.wopi.Access;
import org.olat.core.commons.services.doceditor.wopi.WopiService;
import org.olat.core.commons.services.vfs.VFSMetadata;
import org.olat.core.commons.services.vfs.manager.VFSMetadataDAO;
import org.olat.core.id.Identity;
import org.olat.test.JunitTestHelper;
import org.olat.test.OlatRestTestCase;
import org.springframework.beans.factory.annotation.Autowired;
/**
*
* Initial date: 13 jul. 2020<br>
* @author mjenny, moritz.jenny@frentix.com, http://www.frentix.com
*
*/
public class DocEditorWebServiceTest extends OlatRestTestCase {
@Autowired
private DB dbInstance;
@Autowired
private VFSMetadataDAO vfsMetadataDAO;
@Autowired
private WopiService sut;
@Test
public void docEditorSessionQuery()
throws IOException, URISyntaxException {
RestConnection conn = new RestConnection();
Assert.assertTrue(conn.login("administrator", "openolat"));
VFSMetadata metadata = randomMetadata();
Identity identity = JunitTestHelper.createAndPersistIdentityAsRndUser("wopi");
DocEditorSecurityCallback secCallback = DocEditorSecurityCallbackBuilder.builder().withMode(Mode.EDIT).build();
VFSMetadata metadata2 = randomMetadata();
Identity identity2 = JunitTestHelper.createAndPersistIdentityAsRndUser("wopi2");
DocEditorSecurityCallback secCallback2 = DocEditorSecurityCallbackBuilder.builder().withMode(Mode.VIEW).build();
Access access1 = sut.getOrCreateAccess(metadata, identity, secCallback, "App1", null);
dbInstance.commitAndCloseSession();
Access access2 = sut.getOrCreateAccess(metadata2, identity2, secCallback2, "App1", null);
dbInstance.commitAndCloseSession();
Assert.assertNotNull(access1);
Assert.assertNotNull(access2);
URI request = UriBuilder.fromUri(getContextURI()).path("doceditor").path("sessions").path("App1").build();
HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
DocEditorStatisticsVO docEditorStatisticsVO = conn.parse(response, DocEditorStatisticsVO.class);
Assert.assertEquals(1, docEditorStatisticsVO.getOpenDocumentsRead());
Assert.assertEquals(1, docEditorStatisticsVO.getOpenDocumentsWrite());
}
private VFSMetadata randomMetadata() {
return vfsMetadataDAO.createMetadata(random(), random(), random(), new Date(), 1000l, false, "file://" + random(), "file", null);
}
}
...@@ -425,6 +425,7 @@ import org.junit.runners.Suite; ...@@ -425,6 +425,7 @@ import org.junit.runners.Suite;
org.olat.restapi.CurriculumsWebServiceTest.class, org.olat.restapi.CurriculumsWebServiceTest.class,
org.olat.restapi.CurriculumElementsWebServiceTest.class, org.olat.restapi.CurriculumElementsWebServiceTest.class,
org.olat.restapi.CurriculumElementTypesWebServiceTest.class, org.olat.restapi.CurriculumElementTypesWebServiceTest.class,
org.olat.restapi.DocEditorWebServiceTest.class,
org.olat.restapi.EfficiencyStatementTest.class, org.olat.restapi.EfficiencyStatementTest.class,
org.olat.restapi.FolderTest.class, org.olat.restapi.FolderTest.class,
org.olat.restapi.ForumTest.class, org.olat.restapi.ForumTest.class,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment