Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/464 add extended soft delete #468

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ SPDX-License-Identifier: Apache-2.0
<artifactId>quarkus-container-image-docker</artifactId>
</dependency>

<dependency>
<groupId>io.quarkiverse.openapi.generator</groupId>
<artifactId>quarkus-openapi-generator-server</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>

<!-- Test Dependencies -->
<dependency>
<groupId>io.quarkus</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package org.lfenergy.compas.scl.data.rest.v1;

import io.quarkus.security.Authenticated;
import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import org.lfenergy.compas.scl.data.model.IHistoryMetaItem;
import org.lfenergy.compas.scl.data.model.Version;
import org.lfenergy.compas.scl.data.service.CompasSclHistoryService;
import org.lfenergy.compas.scl.extensions.model.SclFileType;
import org.lfenergy.compas.scl.rest.api.HistoryResource;
import org.lfenergy.compas.scl.rest.api.beans.DataResourceHistory;
import org.lfenergy.compas.scl.rest.api.beans.DataResourceSearch;
import org.lfenergy.compas.scl.rest.api.beans.DataResourcesResult;

import java.time.OffsetDateTime;
import java.util.List;
import java.util.UUID;

@Authenticated
@RequestScoped
@Path("/api")
public class CompasSclHistoryResource implements HistoryResource {

private final CompasSclHistoryService compasSclHistoryService;

@Inject
public CompasSclHistoryResource(CompasSclHistoryService compasSclHistoryService) {
this.compasSclHistoryService = compasSclHistoryService;
}

@Override
public DataResourcesResult searchForResources(DataResourceSearch searchQuery) {
List<IHistoryMetaItem> historyItems = fetchHistoryItems(searchQuery);
DataResourcesResult result = new DataResourcesResult();
result.setResults(historyItems.stream().map(HistoryMapper::convertToDataResource).toList());
return result;
}

@Override
public DataResourceHistory retrieveDataResourceHistory(String id) {
List<IHistoryMetaItem> historyItems = compasSclHistoryService.listHistoryVersionsForResource(UUID.fromString(id));
DataResourceHistory resourcesHistories = new DataResourceHistory();
resourcesHistories.setVersions(historyItems.stream().map(HistoryMapper::convertToDataResourceVersion).toList());
return resourcesHistories;
}

@Override
public Response retrieveDataResourceByVersion(String id, String version) {
String fetchedData = compasSclHistoryService.findFileByIdAndVersion(UUID.fromString(id), new Version(version));
return Response.status(Response.Status.OK).entity(fetchedData).type(MediaType.APPLICATION_XML).build();
}

private List<IHistoryMetaItem> fetchHistoryItems(DataResourceSearch searchQuery) {
String uuid = searchQuery.getUuid();

if (uuid != null) {
return compasSclHistoryService.listHistoryVersionsForResource(UUID.fromString(uuid));
}

SclFileType type = searchQuery.getType() != null ? SclFileType.valueOf(searchQuery.getType()) : null;
String name = searchQuery.getName();
String author = searchQuery.getAuthor();
OffsetDateTime from = DateUtil.convertToOffsetDateTime(searchQuery.getFrom());
OffsetDateTime to = DateUtil.convertToOffsetDateTime(searchQuery.getTo());

if (type != null || name != null || author != null || from != null || to != null) {
return compasSclHistoryService.searchResourcesHistoryVersions(type, name, author, from, to);
}
return compasSclHistoryService.listHistory();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.lfenergy.compas.scl.data.rest.v1;

import org.apache.commons.lang3.ObjectUtils;

import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.util.Date;

public final class DateUtil {

private DateUtil() {
}

public static OffsetDateTime convertToOffsetDateTime(Date date) {
return ObjectUtils.isEmpty(date) ? null : date.toInstant().atOffset(ZoneOffset.UTC);
}

public static Date convertToDate(OffsetDateTime date) {
return ObjectUtils.isEmpty(date) ? null : new Date(date.toInstant().toEpochMilli());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.lfenergy.compas.scl.data.rest.v1;

import org.lfenergy.compas.scl.data.model.IHistoryMetaItem;
import org.lfenergy.compas.scl.rest.api.beans.DataResource;
import org.lfenergy.compas.scl.rest.api.beans.DataResourceVersion;

import java.util.UUID;

public final class HistoryMapper {

private HistoryMapper() {
}

public static DataResourceVersion convertToDataResourceVersion(IHistoryMetaItem item) {
DataResourceVersion version = new DataResourceVersion();
version.setVersion(item.getVersion());
version.setAuthor(item.getAuthor());
version.setName(item.getName());
version.setDeleted(item.isDeleted());
version.setUuid(UUID.fromString(item.getId()));
version.setType(item.getType());
version.setChangedAt(DateUtil.convertToDate(item.getChangedAt()));
version.setComment(item.getComment());
return version;
}

public static DataResource convertToDataResource(IHistoryMetaItem item) {
DataResource version = new DataResource();
version.setVersion(item.getVersion());
version.setAuthor(item.getAuthor());
version.setName(item.getName());
version.setDeleted(item.isDeleted());
version.setUuid(UUID.fromString(item.getId()));
version.setType(item.getType());
version.setChangedAt(DateUtil.convertToDate(item.getChangedAt()));
return version;
}

}
Loading
Loading