From 50973d90a27339621fc0abcb48a8aee465487f3e Mon Sep 17 00:00:00 2001 From: Zachary Sabourin Date: Fri, 19 Aug 2022 15:09:24 -0400 Subject: [PATCH 1/4] feat: Create service to fetch mappers by DTO or model class Issue https://gitlab.eclipse.org/eclipsefdn/it/api/eclipsefdn-api-common/-/issues/12 --- persistence/runtime/pom.xml | 15 +++- .../persistence/dto/mapper/EntityMapper.java | 36 ++++++++++ .../persistence/service/MapperService.java | 24 +++++++ .../service/impl/DefaultMapperService.java | 72 +++++++++++++++++++ 4 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 persistence/runtime/src/main/java/org/eclipsefoundation/persistence/dto/mapper/EntityMapper.java create mode 100644 persistence/runtime/src/main/java/org/eclipsefoundation/persistence/service/MapperService.java create mode 100644 persistence/runtime/src/main/java/org/eclipsefoundation/persistence/service/impl/DefaultMapperService.java diff --git a/persistence/runtime/pom.xml b/persistence/runtime/pom.xml index 85d8fd5..303f981 100644 --- a/persistence/runtime/pom.xml +++ b/persistence/runtime/pom.xml @@ -8,6 +8,9 @@ quarkus-persistence Persistence - Runtime + + 1.5.2.Final + org.eclipsefoundation @@ -30,6 +33,11 @@ org.apache.commons commons-lang3 + + org.mapstruct + mapstruct + ${org.mapstruct.version} + @@ -75,7 +83,7 @@ - + maven-compiler-plugin @@ -85,6 +93,11 @@ quarkus-extension-processor ${quarkus.version} + + org.mapstruct + mapstruct-processor + ${org.mapstruct.version} + diff --git a/persistence/runtime/src/main/java/org/eclipsefoundation/persistence/dto/mapper/EntityMapper.java b/persistence/runtime/src/main/java/org/eclipsefoundation/persistence/dto/mapper/EntityMapper.java new file mode 100644 index 0000000..b29fb48 --- /dev/null +++ b/persistence/runtime/src/main/java/org/eclipsefoundation/persistence/dto/mapper/EntityMapper.java @@ -0,0 +1,36 @@ +/********************************************************************* +* 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/ +* +* SPDX-License-Identifier: EPL-2.0 +**********************************************************************/ +package org.eclipsefoundation.persistence.dto.mapper; + +import org.eclipsefoundation.persistence.dto.BareNode; +import org.mapstruct.InheritInverseConfiguration; + +/** + * Mapper interface to allow mapping of DTOs and Models + */ +public interface EntityMapper { + + S toModel(T dtoEntity); + + @InheritInverseConfiguration + T toDTO(S model); + + /** + * Returns the mapped DTO type. + * @return the class of mapped DTO + */ + Class getDTOType(); + + /** + * Returns the mapped model type. + * @return the class of mapped model + */ + Class getModelType(); +} diff --git a/persistence/runtime/src/main/java/org/eclipsefoundation/persistence/service/MapperService.java b/persistence/runtime/src/main/java/org/eclipsefoundation/persistence/service/MapperService.java new file mode 100644 index 0000000..095dab1 --- /dev/null +++ b/persistence/runtime/src/main/java/org/eclipsefoundation/persistence/service/MapperService.java @@ -0,0 +1,24 @@ +/********************************************************************* +* 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/ +* +* SPDX-License-Identifier: EPL-2.0 +**********************************************************************/ +package org.eclipsefoundation.persistence.service; + +import org.eclipsefoundation.persistence.dto.BareNode; +import org.eclipsefoundation.persistence.dto.mapper.EntityMapper; + +/** + * MapperService interface to allow retrieval of a corresponding EntityMapper. + * Can retrieve an EntityMapper based on target DTO or model class. + */ +public interface MapperService { + + EntityMapper getByModel(Class target); + + EntityMapper getByDTO(Class target); +} diff --git a/persistence/runtime/src/main/java/org/eclipsefoundation/persistence/service/impl/DefaultMapperService.java b/persistence/runtime/src/main/java/org/eclipsefoundation/persistence/service/impl/DefaultMapperService.java new file mode 100644 index 0000000..18c0f0f --- /dev/null +++ b/persistence/runtime/src/main/java/org/eclipsefoundation/persistence/service/impl/DefaultMapperService.java @@ -0,0 +1,72 @@ +/********************************************************************* +* 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/ +* +* SPDX-License-Identifier: EPL-2.0 +**********************************************************************/ +package org.eclipsefoundation.persistence.service.impl; + +import java.util.Optional; + +import javax.enterprise.inject.Instance; +import javax.inject.Inject; + +import org.eclipsefoundation.persistence.dto.BareNode; +import org.eclipsefoundation.persistence.dto.mapper.EntityMapper; +import org.eclipsefoundation.persistence.service.MapperService; + +/** + * Indicates an entity mapping between DTOs and models + * + * @param the DTO object in the mapping pair + * @param the model object in the mapping pair + */ +public class DefaultMapperService implements MapperService { + + @Inject + Instance> mappers; + + /** + * Retrieves an instance of EntityMapper that corresponds to the target model + * class. + * + * @param target The target class used for EntityMapper retrieval + * @return A reference to the target EntityMapper if it exists + */ + @Override + @SuppressWarnings("unchecked") + public EntityMapper getByModel(Class target) { + Optional> mapper = mappers.stream().filter(map -> map.getModelType().equals(target)) + .findFirst(); + + if (mapper.isPresent()) { + return (EntityMapper) mapper.get(); + } + + return null; + } + + /** + * Retrieves an instance of EntityMapper that corresponds to the target DTO + * class. + * + * @param target The target class used for EntityMapper retrieval + * @return A reference to the target EntityMapper if it exists + */ + @Override + @SuppressWarnings("unchecked") + public EntityMapper getByDTO(Class target) { + Optional> mapper = mappers.stream().filter(map -> map.getDTOType().equals(target)) + .findFirst(); + + if (mapper.isPresent()) { + return (EntityMapper) mapper.get(); + } + + return null; + } + +} -- GitLab From 6866e37265dc2250d376710312d2930f39cf7375 Mon Sep 17 00:00:00 2001 From: Zachary Sabourin Date: Fri, 19 Aug 2022 15:34:20 -0400 Subject: [PATCH 2/4] feat: Update javadoc + code cleanup --- .../persistence/dto/mapper/EntityMapper.java | 2 ++ .../persistence/service/MapperService.java | 2 ++ .../service/impl/DefaultMapperService.java | 25 +++++-------------- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/persistence/runtime/src/main/java/org/eclipsefoundation/persistence/dto/mapper/EntityMapper.java b/persistence/runtime/src/main/java/org/eclipsefoundation/persistence/dto/mapper/EntityMapper.java index b29fb48..383e3cf 100644 --- a/persistence/runtime/src/main/java/org/eclipsefoundation/persistence/dto/mapper/EntityMapper.java +++ b/persistence/runtime/src/main/java/org/eclipsefoundation/persistence/dto/mapper/EntityMapper.java @@ -14,6 +14,8 @@ import org.mapstruct.InheritInverseConfiguration; /** * Mapper interface to allow mapping of DTOs and Models + * + * @author Zachary Sabourin */ public interface EntityMapper { diff --git a/persistence/runtime/src/main/java/org/eclipsefoundation/persistence/service/MapperService.java b/persistence/runtime/src/main/java/org/eclipsefoundation/persistence/service/MapperService.java index 095dab1..622c99c 100644 --- a/persistence/runtime/src/main/java/org/eclipsefoundation/persistence/service/MapperService.java +++ b/persistence/runtime/src/main/java/org/eclipsefoundation/persistence/service/MapperService.java @@ -15,6 +15,8 @@ import org.eclipsefoundation.persistence.dto.mapper.EntityMapper; /** * MapperService interface to allow retrieval of a corresponding EntityMapper. * Can retrieve an EntityMapper based on target DTO or model class. + * + * @author Zachary Sabourin */ public interface MapperService { diff --git a/persistence/runtime/src/main/java/org/eclipsefoundation/persistence/service/impl/DefaultMapperService.java b/persistence/runtime/src/main/java/org/eclipsefoundation/persistence/service/impl/DefaultMapperService.java index 18c0f0f..dc280c3 100644 --- a/persistence/runtime/src/main/java/org/eclipsefoundation/persistence/service/impl/DefaultMapperService.java +++ b/persistence/runtime/src/main/java/org/eclipsefoundation/persistence/service/impl/DefaultMapperService.java @@ -9,8 +9,6 @@ **********************************************************************/ package org.eclipsefoundation.persistence.service.impl; -import java.util.Optional; - import javax.enterprise.inject.Instance; import javax.inject.Inject; @@ -21,6 +19,8 @@ import org.eclipsefoundation.persistence.service.MapperService; /** * Indicates an entity mapping between DTOs and models * + * @author Zachary Sabourin + * * @param the DTO object in the mapping pair * @param the model object in the mapping pair */ @@ -39,14 +39,8 @@ public class DefaultMapperService implements MapperServic @Override @SuppressWarnings("unchecked") public EntityMapper getByModel(Class target) { - Optional> mapper = mappers.stream().filter(map -> map.getModelType().equals(target)) - .findFirst(); - - if (mapper.isPresent()) { - return (EntityMapper) mapper.get(); - } - - return null; + return (EntityMapper) mappers.stream().filter(map -> map.getModelType().equals(target)) + .findFirst().orElse(null); } /** @@ -59,14 +53,7 @@ public class DefaultMapperService implements MapperServic @Override @SuppressWarnings("unchecked") public EntityMapper getByDTO(Class target) { - Optional> mapper = mappers.stream().filter(map -> map.getDTOType().equals(target)) - .findFirst(); - - if (mapper.isPresent()) { - return (EntityMapper) mapper.get(); - } - - return null; + return (EntityMapper) mappers.stream().filter(map -> map.getDTOType().equals(target)) + .findFirst().orElse(null); } - } -- GitLab From 57c3cdc9b0070f1cb2b75f41b5ec8385a20ac511 Mon Sep 17 00:00:00 2001 From: Zachary Sabourin Date: Mon, 22 Aug 2022 10:29:33 -0400 Subject: [PATCH 3/4] feat: Add missing javadoc --- .../persistence/service/MapperService.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/persistence/runtime/src/main/java/org/eclipsefoundation/persistence/service/MapperService.java b/persistence/runtime/src/main/java/org/eclipsefoundation/persistence/service/MapperService.java index 622c99c..5eb74db 100644 --- a/persistence/runtime/src/main/java/org/eclipsefoundation/persistence/service/MapperService.java +++ b/persistence/runtime/src/main/java/org/eclipsefoundation/persistence/service/MapperService.java @@ -19,8 +19,22 @@ import org.eclipsefoundation.persistence.dto.mapper.EntityMapper; * @author Zachary Sabourin */ public interface MapperService { - + + /** + * Method to allow retrieval of EntityMapper that corresponds to the target + * model class. + * + * @param target The target class used for EntityMapper retrieval + * @return A reference to the target EntityMapper + */ EntityMapper getByModel(Class target); + /** + * Method to allow retrieval of EntityMapper that corresponds to the target + * DTO class. + * + * @param target The target class used for EntityMapper retrieval + * @return A reference to the target EntityMapper + */ EntityMapper getByDTO(Class target); } -- GitLab From 9ca7169c1fe3cb93175a8ede73155fbb47f3d5b1 Mon Sep 17 00:00:00 2001 From: Zachary Sabourin Date: Thu, 25 Aug 2022 12:19:28 -0400 Subject: [PATCH 4/4] feat: Add testing to MapperService --- .gitignore | 3 +- persistence/runtime/pom.xml | 26 ++++- .../config/QuarkusMappingConfig.java | 17 ++++ .../persistence/dto/mapper/EntityMapper.java | 4 +- .../service/impl/DefaultMapperService.java | 2 + .../service/MapperServiceTest.java | 97 +++++++++++++++++++ .../service/dto/mapper/PersonMapper.java | 40 ++++++++ .../persistence/test/dto/PersonDTO.java | 58 +++++++++++ .../persistence/test/model/PersonModel.java | 43 ++++++++ 9 files changed, 287 insertions(+), 3 deletions(-) create mode 100644 persistence/runtime/src/main/java/org/eclipsefoundation/persistence/config/QuarkusMappingConfig.java create mode 100644 persistence/runtime/src/test/java/org/eclipsefoundation/persistence/service/MapperServiceTest.java create mode 100644 persistence/runtime/src/test/java/org/eclipsefoundation/persistence/service/dto/mapper/PersonMapper.java create mode 100644 persistence/runtime/src/test/java/org/eclipsefoundation/persistence/test/dto/PersonDTO.java create mode 100644 persistence/runtime/src/test/java/org/eclipsefoundation/persistence/test/model/PersonModel.java diff --git a/.gitignore b/.gitignore index 8b6c1c3..b5e3b3e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ target/ .settings/ .project .classpath -bin/ \ No newline at end of file +bin/ +.vscode/ \ No newline at end of file diff --git a/persistence/runtime/pom.xml b/persistence/runtime/pom.xml index 303f981..636f33d 100644 --- a/persistence/runtime/pom.xml +++ b/persistence/runtime/pom.xml @@ -10,12 +10,13 @@ Persistence - Runtime 1.5.2.Final + 1.8.2 org.eclipsefoundation quarkus-core - ${project.version} + ${project.version} io.quarkus @@ -65,6 +66,24 @@ h2 test + + + + com.google.auto.value + auto-value + ${auto-value.version} + provided + + + com.google.auto.value + auto-value-annotations + ${auto-value.version} + + + com.google.code.findbugs + jsr305 + + @@ -98,6 +117,11 @@ mapstruct-processor ${org.mapstruct.version} + + com.google.auto.value + auto-value + ${auto-value.version} + diff --git a/persistence/runtime/src/main/java/org/eclipsefoundation/persistence/config/QuarkusMappingConfig.java b/persistence/runtime/src/main/java/org/eclipsefoundation/persistence/config/QuarkusMappingConfig.java new file mode 100644 index 0000000..37b0c4f --- /dev/null +++ b/persistence/runtime/src/main/java/org/eclipsefoundation/persistence/config/QuarkusMappingConfig.java @@ -0,0 +1,17 @@ +/********************************************************************* +* 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/ +* +* SPDX-License-Identifier: EPL-2.0 +**********************************************************************/ +package org.eclipsefoundation.persistence.config; + +import org.mapstruct.MapperConfig; + +@MapperConfig(componentModel = "cdi") +public interface QuarkusMappingConfig { + +} diff --git a/persistence/runtime/src/main/java/org/eclipsefoundation/persistence/dto/mapper/EntityMapper.java b/persistence/runtime/src/main/java/org/eclipsefoundation/persistence/dto/mapper/EntityMapper.java index 383e3cf..9b6b13d 100644 --- a/persistence/runtime/src/main/java/org/eclipsefoundation/persistence/dto/mapper/EntityMapper.java +++ b/persistence/runtime/src/main/java/org/eclipsefoundation/persistence/dto/mapper/EntityMapper.java @@ -18,7 +18,7 @@ import org.mapstruct.InheritInverseConfiguration; * @author Zachary Sabourin */ public interface EntityMapper { - + S toModel(T dtoEntity); @InheritInverseConfiguration @@ -26,12 +26,14 @@ public interface EntityMapper { /** * Returns the mapped DTO type. + * * @return the class of mapped DTO */ Class getDTOType(); /** * Returns the mapped model type. + * * @return the class of mapped model */ Class getModelType(); diff --git a/persistence/runtime/src/main/java/org/eclipsefoundation/persistence/service/impl/DefaultMapperService.java b/persistence/runtime/src/main/java/org/eclipsefoundation/persistence/service/impl/DefaultMapperService.java index dc280c3..1966687 100644 --- a/persistence/runtime/src/main/java/org/eclipsefoundation/persistence/service/impl/DefaultMapperService.java +++ b/persistence/runtime/src/main/java/org/eclipsefoundation/persistence/service/impl/DefaultMapperService.java @@ -9,6 +9,7 @@ **********************************************************************/ package org.eclipsefoundation.persistence.service.impl; +import javax.enterprise.context.ApplicationScoped; import javax.enterprise.inject.Instance; import javax.inject.Inject; @@ -24,6 +25,7 @@ import org.eclipsefoundation.persistence.service.MapperService; * @param the DTO object in the mapping pair * @param the model object in the mapping pair */ +@ApplicationScoped public class DefaultMapperService implements MapperService { @Inject diff --git a/persistence/runtime/src/test/java/org/eclipsefoundation/persistence/service/MapperServiceTest.java b/persistence/runtime/src/test/java/org/eclipsefoundation/persistence/service/MapperServiceTest.java new file mode 100644 index 0000000..598dd87 --- /dev/null +++ b/persistence/runtime/src/test/java/org/eclipsefoundation/persistence/service/MapperServiceTest.java @@ -0,0 +1,97 @@ +/********************************************************************* +* 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/ +* +* SPDX-License-Identifier: EPL-2.0 +**********************************************************************/ +package org.eclipsefoundation.persistence.service; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import javax.inject.Inject; + +import org.eclipsefoundation.persistence.test.dto.PersonDTO; +import org.eclipsefoundation.persistence.test.model.PersonModel; +import org.junit.jupiter.api.Test; + +import io.quarkus.test.junit.QuarkusTest; + +/** + * Tests the MapperService by attempting to retrieve a Mapper by model and DTO. + * Tests that the retrieved Mapper converts properly in both directions. + * + * @author Zachary Sabourin + */ +@QuarkusTest +public class MapperServiceTest { + + @Inject + MapperService mapperService; + + @Test + public void getMapperByModel() { + assertTrue(mapperService.getByModel(PersonModel.class) != null); + assertTrue(mapperService.getByModel(PersonModel.class).getDTOType() == PersonDTO.class); + } + + @Test + public void getMapperByDTO() { + assertTrue(mapperService.getByDTO(PersonDTO.class) != null); + assertTrue(mapperService.getByDTO(PersonDTO.class).getModelType() == PersonModel.class); + } + + @Test + public void convertToDTO_mapperByModel() { + PersonModel personModel = PersonModel.builder().setAge(25).setName("JimBob").setPersonID("TM-50").build(); + + PersonDTO personDTO = mapperService.getByModel(PersonModel.class).toDTO(personModel); + + assertTrue(personModel.getPersonID().equals(personDTO.getId())); + assertTrue(personModel.getName().equals(personDTO.getName())); + assertTrue(personModel.getAge() == personDTO.getAge()); + } + + @Test + public void convertToDTO_mapperByDTO() { + PersonModel personModel = PersonModel.builder().setAge(25).setName("JimBob").setPersonID("TM-50").build(); + + PersonDTO personDTO = mapperService.getByDTO(PersonDTO.class).toDTO(personModel); + + assertTrue(personModel.getPersonID().equals(personDTO.getId())); + assertTrue(personModel.getName().equals(personDTO.getName())); + assertTrue(personModel.getAge() == personDTO.getAge()); + } + + @Test + public void convertToModel_mapperbyModel() { + + PersonDTO personDTO = new PersonDTO(); + personDTO.setPersonID("TM-50"); + personDTO.setName("JimBob"); + personDTO.setAge(25); + + PersonModel personModel = mapperService.getByModel(PersonModel.class).toModel(personDTO); + + assertTrue(personModel.getPersonID().equals(personDTO.getId())); + assertTrue(personModel.getName().equals(personDTO.getName())); + assertTrue(personModel.getAge() == personDTO.getAge()); + } + + @Test + public void convertToModel_mapperbyDTO() { + + PersonDTO personDTO = new PersonDTO(); + personDTO.setPersonID("TM-50"); + personDTO.setName("JimBob"); + personDTO.setAge(25); + + PersonModel personModel = mapperService.getByDTO(PersonDTO.class).toModel(personDTO); + + assertTrue(personModel.getPersonID().equals(personDTO.getId())); + assertTrue(personModel.getName().equals(personDTO.getName())); + assertTrue(personModel.getAge() == personDTO.getAge()); + } +} diff --git a/persistence/runtime/src/test/java/org/eclipsefoundation/persistence/service/dto/mapper/PersonMapper.java b/persistence/runtime/src/test/java/org/eclipsefoundation/persistence/service/dto/mapper/PersonMapper.java new file mode 100644 index 0000000..af695a7 --- /dev/null +++ b/persistence/runtime/src/test/java/org/eclipsefoundation/persistence/service/dto/mapper/PersonMapper.java @@ -0,0 +1,40 @@ +/********************************************************************* +* 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/ +* +* SPDX-License-Identifier: EPL-2.0 +**********************************************************************/ +package org.eclipsefoundation.persistence.service.dto.mapper; + +import org.eclipsefoundation.persistence.config.QuarkusMappingConfig; +import org.eclipsefoundation.persistence.dto.mapper.EntityMapper; +import org.eclipsefoundation.persistence.test.dto.PersonDTO; +import org.eclipsefoundation.persistence.test.model.PersonModel; +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; + +/** + * A Mapper used for testing. It maps between 2 test entity classes, + * PersonDTO and PersonModel. + */ +@Mapper(config = QuarkusMappingConfig.class) +public interface PersonMapper extends EntityMapper { + + PersonModel toModel(PersonDTO personDTO); + + @InheritInverseConfiguration + PersonDTO toDTO(PersonModel personModel); + + @Override + default Class getDTOType() { + return PersonDTO.class; + } + + @Override + default Class getModelType() { + return PersonModel.class; + } +} \ No newline at end of file diff --git a/persistence/runtime/src/test/java/org/eclipsefoundation/persistence/test/dto/PersonDTO.java b/persistence/runtime/src/test/java/org/eclipsefoundation/persistence/test/dto/PersonDTO.java new file mode 100644 index 0000000..b620409 --- /dev/null +++ b/persistence/runtime/src/test/java/org/eclipsefoundation/persistence/test/dto/PersonDTO.java @@ -0,0 +1,58 @@ +/********************************************************************* +* 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/ +* +* SPDX-License-Identifier: EPL-2.0 +**********************************************************************/ +package org.eclipsefoundation.persistence.test.dto; + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Id; + +import org.eclipsefoundation.persistence.dto.BareNode; + +/** + * A basic DTO class with a few simple fields. Used for testing. + */ +public class PersonDTO extends BareNode implements Serializable { + + @Id + @Column(unique = true, nullable = false) + private String personID; + private String name; + private int age; + + @Override + public Object getId() { + return getPersonID(); + } + + public String getPersonID() { + return this.personID; + } + + public void setPersonID(String id) { + this.personID = id; + } + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + + public int getAge() { + return this.age; + } + + public void setAge(int age) { + this.age = age; + } +} \ No newline at end of file diff --git a/persistence/runtime/src/test/java/org/eclipsefoundation/persistence/test/model/PersonModel.java b/persistence/runtime/src/test/java/org/eclipsefoundation/persistence/test/model/PersonModel.java new file mode 100644 index 0000000..7023d37 --- /dev/null +++ b/persistence/runtime/src/test/java/org/eclipsefoundation/persistence/test/model/PersonModel.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * 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/ + * + * SPDX-License-Identifier: EPL-2.0 + ******************************************************************************/ +package org.eclipsefoundation.persistence.test.model; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.google.auto.value.AutoValue; + +/** + * A basic Model class with a few simple fields. Used for testing. + */ +@AutoValue +@JsonDeserialize(builder = AutoValue_PersonModel.Builder.class) +public abstract class PersonModel { + public abstract String getPersonID(); + + public abstract String getName(); + + public abstract int getAge(); + + public static Builder builder() { + return new AutoValue_PersonModel.Builder(); + } + + @AutoValue.Builder + @JsonPOJOBuilder(withPrefix = "set") + public abstract static class Builder { + public abstract Builder setPersonID(String personID); + + public abstract Builder setName(String name); + + public abstract Builder setAge(int age); + + public abstract PersonModel build(); + } +} \ No newline at end of file -- GitLab