From 1be88222e181dc3b3cc46aa1bcee838c7b7d23f5 Mon Sep 17 00:00:00 2001 From: "swapnil.verma" Date: Fri, 2 Dec 2022 11:46:06 +0530 Subject: [PATCH] [RM-7188] - Added REST endpoint for fetching list of events --- .../rm-public-rest-context.xml | 6 ++ .../rest/api/events/EventEntityResource.java | 78 +++++++++++++++++++ .../rm/rest/api/events/package-info.java | 37 +++++++++ .../alfresco/rm/rest/api/model/EventInfo.java | 78 +++++++++++++++++++ 4 files changed, 199 insertions(+) create mode 100644 amps/ags/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/events/EventEntityResource.java create mode 100644 amps/ags/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/events/package-info.java create mode 100644 amps/ags/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/model/EventInfo.java diff --git a/amps/ags/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-public-rest-context.xml b/amps/ags/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-public-rest-context.xml index b711326ba6..76d7bebb30 100644 --- a/amps/ags/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-public-rest-context.xml +++ b/amps/ags/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-public-rest-context.xml @@ -175,6 +175,10 @@ + + + + @@ -209,6 +213,8 @@ + + diff --git a/amps/ags/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/events/EventEntityResource.java b/amps/ags/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/events/EventEntityResource.java new file mode 100644 index 0000000000..1e3ac9066a --- /dev/null +++ b/amps/ags/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/events/EventEntityResource.java @@ -0,0 +1,78 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2022 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * - + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * - + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * - + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * - + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ + +package org.alfresco.rm.rest.api.events; + +import org.alfresco.module.org_alfresco_module_rm.event.RecordsManagementEventService; +import org.alfresco.rest.framework.WebApiDescription; +import org.alfresco.rest.framework.resource.EntityResource; +import org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction; +import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo; +import org.alfresco.rest.framework.resource.parameters.Paging; +import org.alfresco.rest.framework.resource.parameters.Parameters; +import org.alfresco.rm.rest.api.model.EventInfo; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * Event entity resource + * + * @author Swapnil Verma + * @since 2.6 + */ +@EntityResource(name = "events", title = "Events") +public class EventEntityResource implements EntityResourceAction.Read { + private RecordsManagementEventService recordsManagementEventService; + + /** + * Set the records management event service + * + * @param rmEventService Records management event service + */ + public void setRecordsManagementEventService(RecordsManagementEventService rmEventService) + { + this.recordsManagementEventService = rmEventService; + } + + @Override + @WebApiDescription(title = "Return a list of events") + public CollectionWithPagingInfo readAll(Parameters params) { + Paging paging = params.getPaging(); + + List eventInfoList = recordsManagementEventService.getEvents().stream() + .map(EventInfo::fromRecordsManagementEvent) + .collect(Collectors.toList()); + + int totalCount = eventInfoList.size(); + boolean hasMoreItems = paging.getSkipCount() + paging.getMaxItems() < totalCount; + return CollectionWithPagingInfo.asPaged(paging, eventInfoList.stream() + .skip(paging.getSkipCount()) + .limit(paging.getMaxItems()) + .collect(Collectors.toList()), hasMoreItems, totalCount); + } +} diff --git a/amps/ags/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/events/package-info.java b/amps/ags/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/events/package-info.java new file mode 100644 index 0000000000..80b0e356f0 --- /dev/null +++ b/amps/ags/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/events/package-info.java @@ -0,0 +1,37 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * - + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * - + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * - + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * - + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ + +/** + * Package info that defines the Information Governance Events REST API + * + * @author Swapnil Verma + * @since 2.6 + */ +@WebApi(name="gs", scope=Api.SCOPE.PUBLIC, version=1) +package org.alfresco.rm.rest.api.events; +import org.alfresco.rest.framework.Api; +import org.alfresco.rest.framework.WebApi; \ No newline at end of file diff --git a/amps/ags/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/model/EventInfo.java b/amps/ags/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/model/EventInfo.java new file mode 100644 index 0000000000..177740cc39 --- /dev/null +++ b/amps/ags/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/model/EventInfo.java @@ -0,0 +1,78 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2022 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * - + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * - + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * - + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * - + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ + +package org.alfresco.rm.rest.api.model; + +import org.alfresco.module.org_alfresco_module_rm.event.RecordsManagementEvent; + +/** + * The EventInfo model to be exposed through REST API. + * + * @author Swapnil Verma + * @since 7.3.0 + */ +public class EventInfo { + private String id; + private String name; + private String type; + + public static EventInfo fromRecordsManagementEvent(RecordsManagementEvent event) { + EventInfo eventInfo = new EventInfo(); + if (event != null) { + eventInfo.setName(event.getDisplayLabel()); + eventInfo.setId(event.getName()); + eventInfo.setType(event.getType()); + } + return eventInfo; + } + + public EventInfo() {} + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } +}