Skip to content
Snippets Groups Projects
Commit 68609ffb authored by Martin Lowe's avatar Martin Lowe :flag_ca:
Browse files

Merge branch 'zacharysabourin/master/81' into 'master'

feat: Modify reports output model + update spec

See merge request !115
parents 2c75727e d7867562
No related branches found
No related tags found
1 merge request!115feat: Modify reports output model + update spec
Pipeline #13501 passed
......@@ -17,6 +17,7 @@
<quarkus.platform.version>2.9.2.Final</quarkus.platform.version>
<surefire-plugin.version>2.22.1</surefire-plugin.version>
<auto-value.version>1.8.2</auto-value.version>
<org.mapstruct.version>1.4.1.Final</org.mapstruct.version>
</properties>
<repositories>
<repository>
......@@ -95,6 +96,17 @@
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>${org.mapstruct.version}</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
<scope>provided</scope>
</dependency>
<!-- Third-party reqs -->
<dependency>
......@@ -202,6 +214,11 @@
<artifactId>auto-value</artifactId>
<version>${auto-value.version}</version>
</path>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
......
......@@ -381,13 +381,20 @@ components:
PrivateProjectEvents:
type: array
items:
$ref: "#/components/schemas/PrivateProjectEvent"
$ref: "#/components/schemas/PrivateProjectData"
PrivateProjectEvent:
PrivateProjectData:
type: object
properties:
composite_id:
$ref: "#/components/schemas/EventCompositeId"
user_id:
type: integer
description: the project creator's GitLab id
project_id:
type: integer
description: The project GitLab id
project_path:
type: string
description: the project's path with namespace
parent_project:
type:
- integer
......@@ -402,19 +409,6 @@ components:
- "null"
description: the project deletion date if it was deleted
EventCompositeId:
type: object
properties:
user_id:
type: integer
description: the project creator's GitLab id
project_id:
type: integer
description: The project GitLab id
project_path:
type: string
description: the project's path with namespace
Error:
type: object
properties:
......
/*********************************************************************
* Copyright (c) 2022 Eclipse Foundation.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* Author: Zachary Sabourin <zachary.sabourin@eclipse-foundation.org>
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
package org.eclipsefoundation.git.eca.model;
import java.time.LocalDateTime;
import javax.annotation.Nullable;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
import com.google.auto.value.AutoValue;
@AutoValue
@JsonDeserialize(builder = AutoValue_PrivateProjectData.Builder.class)
public abstract class PrivateProjectData {
public abstract Integer getUserId();
public abstract Integer getProjectId();
public abstract String getProjectPath();
@Nullable
public abstract Integer getParentProject();
public abstract LocalDateTime getCreationDate();
@Nullable
public abstract LocalDateTime getDeletionDate();
public static Builder builder() {
return new AutoValue_PrivateProjectData.Builder();
}
@AutoValue.Builder
@JsonPOJOBuilder(withPrefix = "set")
public abstract static class Builder {
public abstract Builder setUserId(Integer id);
public abstract Builder setProjectId(Integer id);
public abstract Builder setProjectPath(String path);
public abstract Builder setParentProject(@Nullable Integer id);
public abstract Builder setCreationDate(LocalDateTime time);
public abstract Builder setDeletionDate(@Nullable LocalDateTime time);
public abstract PrivateProjectData build();
}
}
/*********************************************************************
* Copyright (c) 2022 Eclipse Foundation.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* Author: Martin Lowe <martin.lowe@eclipse-foundation.org>
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
package org.eclipsefoundation.git.eca.model.mappers;
import org.eclipsefoundation.persistence.dao.PersistenceDao;
import org.eclipsefoundation.persistence.dto.BareNode;
import org.mapstruct.Context;
import org.mapstruct.InheritInverseConfiguration;
import org.mapstruct.MapperConfig;
import org.mapstruct.ObjectFactory;
import org.mapstruct.TargetType;
/**
* Indicates an entity mapping between DTOs and models. Is used to help simplify
* the lookups where possible.
*
* @author Martin Lowe
*
* @param <T> the DTO object in the mapping pair
* @param <U> the model object in the mapping pair
*/
public interface BaseEntityMapper<T extends BareNode, U> {
U toModel(T dtoEntity);
@InheritInverseConfiguration
T toDTO(U model, @Context PersistenceDao repo);
/**
* Used for generic BareNode lookups. This assumes that the string in the
* inverse is the key of the field. This will
* be used in a lookup of a reference of the object to be used in the DTO mapped
* object.
*
* @param <E> the BareNode actual type
* @param id the string ID of the object to lookup
* @param repo the passed repo context to be used for reference lookups
* @param targetType the injected class type reference
* @return a reference to the target entity if it exists, or a new object to be
* persisted.
*/
@ObjectFactory
default <E extends BareNode> E lookup(String id, @Context PersistenceDao repo, @TargetType Class<E> targetType) {
E entity = repo.getReference(id, targetType);
if (entity == null) {
try {
entity = targetType.getConstructor().newInstance();
} catch (Exception e) {
throw new IllegalStateException("Could not access no-param constructor of entity type", e);
}
}
return entity;
}
}
/*********************************************************************
* Copyright (c) 2022 Eclipse Foundation.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* Author: Zachary Sabourin <zachary.sabourin@eclipse-foundation.org>
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
package org.eclipsefoundation.git.eca.model.mappers;
import org.eclipsefoundation.git.eca.dto.PrivateProjectEvent;
import org.eclipsefoundation.git.eca.model.PrivateProjectData;
import org.eclipsefoundation.persistence.config.QuarkusMappingConfig;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
@Mapper(config = QuarkusMappingConfig.class)
public interface PrivateProjectEventMapper extends BaseEntityMapper<PrivateProjectEvent, PrivateProjectData> {
@Mapping(source = "compositeId.userId", target = "userId")
@Mapping(source = "compositeId.projectId", target = "projectId")
@Mapping(source = "compositeId.projectPath", target = "projectPath")
PrivateProjectData toModel(PrivateProjectEvent dto);
}
......@@ -15,7 +15,7 @@ import java.time.LocalDate;
import java.util.List;
import org.eclipsefoundation.core.model.RequestWrapper;
import org.eclipsefoundation.git.eca.dto.PrivateProjectEvent;
import org.eclipsefoundation.git.eca.model.PrivateProjectData;
/**
* This interface provides the means to get list of desired entities from the DB
......@@ -31,8 +31,8 @@ public interface ReportsService {
* @param status The current project status
* @param since The starting range
* @param until The ending range
* @return A List of PrivateProjectEvent entities
* @return A List of PrivateProjectData entities
*/
public List<PrivateProjectEvent> getPrivateProjectEvents(RequestWrapper wrap, String status, LocalDate since,
public List<PrivateProjectData> getPrivateProjectEvents(RequestWrapper wrap, String status, LocalDate since,
LocalDate until);
}
......@@ -14,6 +14,7 @@ package org.eclipsefoundation.git.eca.service.impl;
import java.time.LocalDate;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
......@@ -22,6 +23,8 @@ import javax.ws.rs.core.MultivaluedMap;
import org.apache.commons.lang3.StringUtils;
import org.eclipsefoundation.core.model.RequestWrapper;
import org.eclipsefoundation.git.eca.dto.PrivateProjectEvent;
import org.eclipsefoundation.git.eca.model.PrivateProjectData;
import org.eclipsefoundation.git.eca.model.mappers.PrivateProjectEventMapper;
import org.eclipsefoundation.git.eca.namespace.GitEcaParameterNames;
import org.eclipsefoundation.git.eca.service.ReportsService;
import org.eclipsefoundation.persistence.dao.PersistenceDao;
......@@ -41,8 +44,12 @@ public class DefaultReportsService implements ReportsService {
@Inject
FilterService filters;
@Inject
PrivateProjectEventMapper mapper;
@Override
public List<PrivateProjectEvent> getPrivateProjectEvents(RequestWrapper wrap, String status, LocalDate since, LocalDate until) {
public List<PrivateProjectData> getPrivateProjectEvents(RequestWrapper wrap, String status, LocalDate since,
LocalDate until) {
MultivaluedMap<String, String> params = new MultivaluedMapImpl<>();
......@@ -67,7 +74,7 @@ public class DefaultReportsService implements ReportsService {
return Collections.emptyList();
}
return results;
// Map to models
return results.stream().map(mapper::toModel).collect(Collectors.toList());
}
}
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