Loading src/main/java/es/redmic/usersettingslib/dto/SettingsDTO.java→src/main/java/es/redmic/usersettingslib/dto/SaveDTO.java +12 −120 Original line number Diff line number Diff line Loading @@ -20,8 +20,6 @@ package es.redmic.usersettingslib.dto; * #L% */ import java.util.List; import javax.validation.constraints.NotNull; import org.apache.avro.Schema; Loading @@ -29,25 +27,17 @@ import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.kjetland.jackson.jsonSchema.annotations.JsonSchemaDefault; import es.redmic.brokerlib.avro.common.CommonDTO; import es.redmic.brokerlib.deserializer.CustomDateTimeDeserializer; import es.redmic.brokerlib.serializer.CustomDateTimeSerializer; public class SettingsDTO extends CommonDTO { public class SaveDTO extends SettingsBaseDTO { // @formatter:off @JsonIgnore public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse( "{\"type\":\"record\",\"name\":\"SettingsDTO\",\"namespace\":\"es.redmic.usersettingslib.dto\",\"fields\":[" "{\"type\":\"record\",\"name\":\"SaveDTO\",\"namespace\":\"es.redmic.usersettingslib.dto\",\"fields\":[" + "{\"name\":\"name\",\"type\":[\"string\", \"null\"]}," + "{\"name\":\"shared\",\"type\":\"boolean\", \"default\": \"false\"}," + "{\"name\": \"selection\",\"type\": [{\"type\": \"array\",\"items\":\"string\"},\"null\"]}," + "{\"name\":\"service\",\"type\":\"string\"}," + "{\"name\":\"userId\",\"type\":[\"string\", \"null\"]}," + "{\"name\":\"inserted\",\"type\":[\"null\",{\"type\":\"long\",\"logicalType\":\"timestamp-millis\"}]," + "\"default\": null}," Loading @@ -58,7 +48,7 @@ public class SettingsDTO extends CommonDTO { + "{\"name\":\"id\",\"type\":\"string\"}]}"); // @formatter:on public SettingsDTO() { public SaveDTO() { super(); } Loading @@ -68,25 +58,8 @@ public class SettingsDTO extends CommonDTO { @NotNull private Boolean shared = false; private List<String> selection; @NotNull private String service; private String userId; @JsonSerialize(using = CustomDateTimeSerializer.class) @JsonDeserialize(using = CustomDateTimeDeserializer.class) private DateTime inserted; @JsonSerialize(using = CustomDateTimeSerializer.class) @JsonDeserialize(using = CustomDateTimeDeserializer.class) private DateTime updated; @JsonSerialize(using = CustomDateTimeSerializer.class) @JsonDeserialize(using = CustomDateTimeDeserializer.class) DateTime accessed; public String getName() { return name; } Loading @@ -103,22 +76,6 @@ public class SettingsDTO extends CommonDTO { this.shared = shared; } public List<String> getSelection() { return selection; } public void setSelection(List<String> selection) { this.selection = selection; } public String getService() { return service; } public void setService(String service) { this.service = service; } public String getUserId() { return userId; } Loading @@ -127,41 +84,12 @@ public class SettingsDTO extends CommonDTO { this.userId = userId; } public DateTime getInserted() { return inserted; } public void setInserted(DateTime inserted) { this.inserted = inserted; } public DateTime getUpdated() { return updated; } public void setUpdated(DateTime updated) { this.updated = updated; } public DateTime getAccessed() { return accessed; } public void setAccessed(DateTime accessed) { this.accessed = accessed; } @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((accessed == null) ? 0 : accessed.hashCode()); result = prime * result + ((inserted == null) ? 0 : inserted.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((selection == null) ? 0 : selection.hashCode()); result = prime * result + ((service == null) ? 0 : service.hashCode()); result = prime * result + ((shared == null) ? 0 : shared.hashCode()); result = prime * result + ((updated == null) ? 0 : updated.hashCode()); result = prime * result + ((userId == null) ? 0 : userId.hashCode()); return result; } Loading @@ -174,42 +102,17 @@ public class SettingsDTO extends CommonDTO { return false; if (getClass() != obj.getClass()) return false; SettingsDTO other = (SettingsDTO) obj; if (accessed == null) { if (other.accessed != null) return false; } else if (!accessed.equals(other.accessed)) return false; if (inserted == null) { if (other.inserted != null) return false; } else if (!inserted.equals(other.inserted)) return false; SaveDTO other = (SaveDTO) obj; if (name == null) { if (other.name != null) return false; } else if (!name.equals(other.name)) return false; if (selection == null) { if (other.selection != null) return false; } else if (!selection.equals(other.selection)) return false; if (service == null) { if (other.service != null) return false; } else if (!service.equals(other.service)) return false; if (shared == null) { if (other.shared != null) return false; } else if (!shared.equals(other.shared)) return false; if (updated == null) { if (other.updated != null) return false; } else if (!updated.equals(other.updated)) return false; if (userId == null) { if (other.userId != null) return false; Loading @@ -233,25 +136,20 @@ public class SettingsDTO extends CommonDTO { case 1: return getShared(); case 2: return getSelection(); case 3: return getService(); case 4: return getUserId(); case 5: case 3: return getInserted() != null ? getInserted().getMillis() : null; case 6: case 4: return getUpdated() != null ? getUpdated().getMillis() : null; case 7: case 5: return getAccessed() != null ? getAccessed().getMillis() : null; case 8: case 6: return getId(); default: throw new org.apache.avro.AvroRuntimeException("Bad index"); } } @SuppressWarnings({ "unchecked", "rawtypes" }) @JsonIgnore @Override public void put(int field, Object value) { Loading @@ -263,24 +161,18 @@ public class SettingsDTO extends CommonDTO { setShared(value != null ? (boolean) value : null); break; case 2: setSelection(value != null ? (java.util.List) value : null); break; case 3: setService(value.toString()); break; case 4: setUserId(value != null ? value.toString() : null); break; case 5: case 3: setInserted(value != null ? new DateTime(value, DateTimeZone.UTC).toDateTime() : null); break; case 6: case 4: setUpdated(value != null ? new DateTime(value, DateTimeZone.UTC).toDateTime() : null); break; case 7: case 5: setAccessed(value != null ? new DateTime(value, DateTimeZone.UTC).toDateTime() : null); break; case 8: case 6: setId(value.toString()); break; default: Loading src/main/java/es/redmic/usersettingslib/dto/SelectionDTO.java 0 → 100644 +161 −0 Original line number Diff line number Diff line package es.redmic.usersettingslib.dto; /*- * #%L * user-settings-lib * %% * Copyright (C) 2019 REDMIC Project / Server * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * #L% */ import java.util.List; import javax.validation.constraints.NotNull; import org.apache.avro.Schema; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import com.fasterxml.jackson.annotation.JsonIgnore; public class SelectionDTO extends SettingsBaseDTO { // @formatter:off @JsonIgnore public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse( "{\"type\":\"record\",\"name\":\"SelectionDTO\",\"namespace\":\"es.redmic.usersettingslib.dto\",\"fields\":[" + "{\"name\": \"selection\",\"type\": [{\"type\": \"array\",\"items\":\"string\"},\"null\"]}," + "{\"name\":\"service\",\"type\":\"string\"}," + "{\"name\":\"inserted\",\"type\":[\"null\",{\"type\":\"long\",\"logicalType\":\"timestamp-millis\"}]," + "\"default\": null}," + "{\"name\":\"updated\",\"type\":[\"null\",{\"type\":\"long\",\"logicalType\":\"timestamp-millis\"}]," + "\"default\": null}," + "{\"name\":\"accessed\",\"type\":[\"null\",{\"type\":\"long\",\"logicalType\":\"timestamp-millis\"}]," + "\"default\": null}," + "{\"name\":\"id\",\"type\":\"string\"}]}"); // @formatter:on public SelectionDTO() { super(); } private List<String> selection; @NotNull private String service; public List<String> getSelection() { return selection; } public void setSelection(List<String> selection) { this.selection = selection; } public String getService() { return service; } public void setService(String service) { this.service = service; } @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((selection == null) ? 0 : selection.hashCode()); result = prime * result + ((service == null) ? 0 : service.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; SelectionDTO other = (SelectionDTO) obj; if (selection == null) { if (other.selection != null) return false; } else if (!selection.equals(other.selection)) return false; if (service == null) { if (other.service != null) return false; } else if (!service.equals(other.service)) return false; return true; } @JsonIgnore @Override public Schema getSchema() { return SCHEMA$; } @JsonIgnore @Override public Object get(int field) { switch (field) { case 0: return getSelection(); case 1: return getService(); case 2: return getInserted() != null ? getInserted().getMillis() : null; case 3: return getUpdated() != null ? getUpdated().getMillis() : null; case 4: return getAccessed() != null ? getAccessed().getMillis() : null; case 5: return getId(); default: throw new org.apache.avro.AvroRuntimeException("Bad index"); } } @SuppressWarnings({ "unchecked", "rawtypes" }) @JsonIgnore @Override public void put(int field, Object value) { switch (field) { case 0: setSelection(value != null ? (java.util.List) value : null); break; case 1: setService(value.toString()); break; case 2: setInserted(value != null ? new DateTime(value, DateTimeZone.UTC).toDateTime() : null); break; case 3: setUpdated(value != null ? new DateTime(value, DateTimeZone.UTC).toDateTime() : null); break; case 4: setAccessed(value != null ? new DateTime(value, DateTimeZone.UTC).toDateTime() : null); break; case 5: setId(value.toString()); break; default: throw new org.apache.avro.AvroRuntimeException("Bad index"); } } } src/main/java/es/redmic/usersettingslib/dto/SettingsBaseDTO.java 0 → 100644 +110 −0 Original line number Diff line number Diff line package es.redmic.usersettingslib.dto; /*- * #%L * user-settings-lib * %% * Copyright (C) 2019 REDMIC Project / Server * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * #L% */ import org.joda.time.DateTime; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import es.redmic.brokerlib.avro.common.CommonDTO; import es.redmic.brokerlib.deserializer.CustomDateTimeDeserializer; import es.redmic.brokerlib.serializer.CustomDateTimeSerializer; public abstract class SettingsBaseDTO extends CommonDTO { public SettingsBaseDTO() { super(); } @JsonSerialize(using = CustomDateTimeSerializer.class) @JsonDeserialize(using = CustomDateTimeDeserializer.class) private DateTime inserted; @JsonSerialize(using = CustomDateTimeSerializer.class) @JsonDeserialize(using = CustomDateTimeDeserializer.class) private DateTime updated; @JsonSerialize(using = CustomDateTimeSerializer.class) @JsonDeserialize(using = CustomDateTimeDeserializer.class) DateTime accessed; public DateTime getInserted() { return inserted; } public void setInserted(DateTime inserted) { this.inserted = inserted; } public DateTime getUpdated() { return updated; } public void setUpdated(DateTime updated) { this.updated = updated; } public DateTime getAccessed() { return accessed; } public void setAccessed(DateTime accessed) { this.accessed = accessed; } @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((accessed == null) ? 0 : accessed.hashCode()); result = prime * result + ((inserted == null) ? 0 : inserted.hashCode()); result = prime * result + ((updated == null) ? 0 : updated.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; SettingsBaseDTO other = (SettingsBaseDTO) obj; if (accessed == null) { if (other.accessed != null) return false; } else if (!accessed.equals(other.accessed)) return false; if (inserted == null) { if (other.inserted != null) return false; } else if (!inserted.equals(other.inserted)) return false; if (updated == null) { if (other.updated != null) return false; } else if (!updated.equals(other.updated)) return false; return true; } } src/test/java/es/redmic/usersettingslib/unit/dto/SettingsCheckAvroSchemaTest.java→src/test/java/es/redmic/usersettingslib/unit/dto/SaveCheckAvroSchemaTest.java +4 −4 Original line number Diff line number Diff line Loading @@ -27,19 +27,19 @@ import org.junit.Test; import org.skyscreamer.jsonassert.JSONAssert; import es.redmic.testutils.utils.AvroBaseTest; import es.redmic.usersettingslib.dto.SettingsDTO; import es.redmic.usersettingslib.dto.SaveDTO; import es.redmic.usersettingslib.unit.utils.SettingsDataUtil; public class SettingsCheckAvroSchemaTest extends AvroBaseTest { public class SaveCheckAvroSchemaTest extends AvroBaseTest { @Test public void serializeAndDeserialize_IsSuccessful_IfSchemaAndDataAreCorrect() throws JSONException { SettingsDTO dto = SettingsDataUtil.getSettings(); SaveDTO dto = SettingsDataUtil.getSaveDTO(); Object result = serializerAndDeserializer(dto); assertTrue("El objeto obtenido debe ser una instancia de SettingsDTO", SettingsDTO.class.isInstance(result)); assertTrue("El objeto obtenido debe ser una instancia de SaveDTO", SaveDTO.class.isInstance(result)); JSONAssert.assertEquals(result.toString(), dto.toString(), false); } Loading src/test/java/es/redmic/usersettingslib/unit/dto/SaveCheckDTOValidationTest.java 0 → 100644 +53 −0 Original line number Diff line number Diff line package es.redmic.usersettingslib.unit.dto; /*- * #%L * user-settings-lib * %% * Copyright (C) 2019 REDMIC Project / Server * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * #L% */ import org.junit.Before; import org.junit.Test; import es.redmic.testutils.dto.DTOBaseTest; import es.redmic.usersettingslib.dto.SaveDTO; import es.redmic.usersettingslib.unit.utils.SettingsDataUtil; public class SaveCheckDTOValidationTest extends DTOBaseTest<SaveDTO> { private static SaveDTO dto; @Before public void reset() { dto = SettingsDataUtil.getSaveDTO(); } @Test public void validationDTO_NoReturnError_IfDTOIsCorrect() { checkDTOHasNoError(dto); } @Test public void validationDTO_ReturnError_IfSharedIsNull() { dto.setShared(null); checkDTOHasError(dto, NOT_NULL_MESSAGE_TEMPLATE); } } Loading
src/main/java/es/redmic/usersettingslib/dto/SettingsDTO.java→src/main/java/es/redmic/usersettingslib/dto/SaveDTO.java +12 −120 Original line number Diff line number Diff line Loading @@ -20,8 +20,6 @@ package es.redmic.usersettingslib.dto; * #L% */ import java.util.List; import javax.validation.constraints.NotNull; import org.apache.avro.Schema; Loading @@ -29,25 +27,17 @@ import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.kjetland.jackson.jsonSchema.annotations.JsonSchemaDefault; import es.redmic.brokerlib.avro.common.CommonDTO; import es.redmic.brokerlib.deserializer.CustomDateTimeDeserializer; import es.redmic.brokerlib.serializer.CustomDateTimeSerializer; public class SettingsDTO extends CommonDTO { public class SaveDTO extends SettingsBaseDTO { // @formatter:off @JsonIgnore public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse( "{\"type\":\"record\",\"name\":\"SettingsDTO\",\"namespace\":\"es.redmic.usersettingslib.dto\",\"fields\":[" "{\"type\":\"record\",\"name\":\"SaveDTO\",\"namespace\":\"es.redmic.usersettingslib.dto\",\"fields\":[" + "{\"name\":\"name\",\"type\":[\"string\", \"null\"]}," + "{\"name\":\"shared\",\"type\":\"boolean\", \"default\": \"false\"}," + "{\"name\": \"selection\",\"type\": [{\"type\": \"array\",\"items\":\"string\"},\"null\"]}," + "{\"name\":\"service\",\"type\":\"string\"}," + "{\"name\":\"userId\",\"type\":[\"string\", \"null\"]}," + "{\"name\":\"inserted\",\"type\":[\"null\",{\"type\":\"long\",\"logicalType\":\"timestamp-millis\"}]," + "\"default\": null}," Loading @@ -58,7 +48,7 @@ public class SettingsDTO extends CommonDTO { + "{\"name\":\"id\",\"type\":\"string\"}]}"); // @formatter:on public SettingsDTO() { public SaveDTO() { super(); } Loading @@ -68,25 +58,8 @@ public class SettingsDTO extends CommonDTO { @NotNull private Boolean shared = false; private List<String> selection; @NotNull private String service; private String userId; @JsonSerialize(using = CustomDateTimeSerializer.class) @JsonDeserialize(using = CustomDateTimeDeserializer.class) private DateTime inserted; @JsonSerialize(using = CustomDateTimeSerializer.class) @JsonDeserialize(using = CustomDateTimeDeserializer.class) private DateTime updated; @JsonSerialize(using = CustomDateTimeSerializer.class) @JsonDeserialize(using = CustomDateTimeDeserializer.class) DateTime accessed; public String getName() { return name; } Loading @@ -103,22 +76,6 @@ public class SettingsDTO extends CommonDTO { this.shared = shared; } public List<String> getSelection() { return selection; } public void setSelection(List<String> selection) { this.selection = selection; } public String getService() { return service; } public void setService(String service) { this.service = service; } public String getUserId() { return userId; } Loading @@ -127,41 +84,12 @@ public class SettingsDTO extends CommonDTO { this.userId = userId; } public DateTime getInserted() { return inserted; } public void setInserted(DateTime inserted) { this.inserted = inserted; } public DateTime getUpdated() { return updated; } public void setUpdated(DateTime updated) { this.updated = updated; } public DateTime getAccessed() { return accessed; } public void setAccessed(DateTime accessed) { this.accessed = accessed; } @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((accessed == null) ? 0 : accessed.hashCode()); result = prime * result + ((inserted == null) ? 0 : inserted.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((selection == null) ? 0 : selection.hashCode()); result = prime * result + ((service == null) ? 0 : service.hashCode()); result = prime * result + ((shared == null) ? 0 : shared.hashCode()); result = prime * result + ((updated == null) ? 0 : updated.hashCode()); result = prime * result + ((userId == null) ? 0 : userId.hashCode()); return result; } Loading @@ -174,42 +102,17 @@ public class SettingsDTO extends CommonDTO { return false; if (getClass() != obj.getClass()) return false; SettingsDTO other = (SettingsDTO) obj; if (accessed == null) { if (other.accessed != null) return false; } else if (!accessed.equals(other.accessed)) return false; if (inserted == null) { if (other.inserted != null) return false; } else if (!inserted.equals(other.inserted)) return false; SaveDTO other = (SaveDTO) obj; if (name == null) { if (other.name != null) return false; } else if (!name.equals(other.name)) return false; if (selection == null) { if (other.selection != null) return false; } else if (!selection.equals(other.selection)) return false; if (service == null) { if (other.service != null) return false; } else if (!service.equals(other.service)) return false; if (shared == null) { if (other.shared != null) return false; } else if (!shared.equals(other.shared)) return false; if (updated == null) { if (other.updated != null) return false; } else if (!updated.equals(other.updated)) return false; if (userId == null) { if (other.userId != null) return false; Loading @@ -233,25 +136,20 @@ public class SettingsDTO extends CommonDTO { case 1: return getShared(); case 2: return getSelection(); case 3: return getService(); case 4: return getUserId(); case 5: case 3: return getInserted() != null ? getInserted().getMillis() : null; case 6: case 4: return getUpdated() != null ? getUpdated().getMillis() : null; case 7: case 5: return getAccessed() != null ? getAccessed().getMillis() : null; case 8: case 6: return getId(); default: throw new org.apache.avro.AvroRuntimeException("Bad index"); } } @SuppressWarnings({ "unchecked", "rawtypes" }) @JsonIgnore @Override public void put(int field, Object value) { Loading @@ -263,24 +161,18 @@ public class SettingsDTO extends CommonDTO { setShared(value != null ? (boolean) value : null); break; case 2: setSelection(value != null ? (java.util.List) value : null); break; case 3: setService(value.toString()); break; case 4: setUserId(value != null ? value.toString() : null); break; case 5: case 3: setInserted(value != null ? new DateTime(value, DateTimeZone.UTC).toDateTime() : null); break; case 6: case 4: setUpdated(value != null ? new DateTime(value, DateTimeZone.UTC).toDateTime() : null); break; case 7: case 5: setAccessed(value != null ? new DateTime(value, DateTimeZone.UTC).toDateTime() : null); break; case 8: case 6: setId(value.toString()); break; default: Loading
src/main/java/es/redmic/usersettingslib/dto/SelectionDTO.java 0 → 100644 +161 −0 Original line number Diff line number Diff line package es.redmic.usersettingslib.dto; /*- * #%L * user-settings-lib * %% * Copyright (C) 2019 REDMIC Project / Server * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * #L% */ import java.util.List; import javax.validation.constraints.NotNull; import org.apache.avro.Schema; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import com.fasterxml.jackson.annotation.JsonIgnore; public class SelectionDTO extends SettingsBaseDTO { // @formatter:off @JsonIgnore public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse( "{\"type\":\"record\",\"name\":\"SelectionDTO\",\"namespace\":\"es.redmic.usersettingslib.dto\",\"fields\":[" + "{\"name\": \"selection\",\"type\": [{\"type\": \"array\",\"items\":\"string\"},\"null\"]}," + "{\"name\":\"service\",\"type\":\"string\"}," + "{\"name\":\"inserted\",\"type\":[\"null\",{\"type\":\"long\",\"logicalType\":\"timestamp-millis\"}]," + "\"default\": null}," + "{\"name\":\"updated\",\"type\":[\"null\",{\"type\":\"long\",\"logicalType\":\"timestamp-millis\"}]," + "\"default\": null}," + "{\"name\":\"accessed\",\"type\":[\"null\",{\"type\":\"long\",\"logicalType\":\"timestamp-millis\"}]," + "\"default\": null}," + "{\"name\":\"id\",\"type\":\"string\"}]}"); // @formatter:on public SelectionDTO() { super(); } private List<String> selection; @NotNull private String service; public List<String> getSelection() { return selection; } public void setSelection(List<String> selection) { this.selection = selection; } public String getService() { return service; } public void setService(String service) { this.service = service; } @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((selection == null) ? 0 : selection.hashCode()); result = prime * result + ((service == null) ? 0 : service.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; SelectionDTO other = (SelectionDTO) obj; if (selection == null) { if (other.selection != null) return false; } else if (!selection.equals(other.selection)) return false; if (service == null) { if (other.service != null) return false; } else if (!service.equals(other.service)) return false; return true; } @JsonIgnore @Override public Schema getSchema() { return SCHEMA$; } @JsonIgnore @Override public Object get(int field) { switch (field) { case 0: return getSelection(); case 1: return getService(); case 2: return getInserted() != null ? getInserted().getMillis() : null; case 3: return getUpdated() != null ? getUpdated().getMillis() : null; case 4: return getAccessed() != null ? getAccessed().getMillis() : null; case 5: return getId(); default: throw new org.apache.avro.AvroRuntimeException("Bad index"); } } @SuppressWarnings({ "unchecked", "rawtypes" }) @JsonIgnore @Override public void put(int field, Object value) { switch (field) { case 0: setSelection(value != null ? (java.util.List) value : null); break; case 1: setService(value.toString()); break; case 2: setInserted(value != null ? new DateTime(value, DateTimeZone.UTC).toDateTime() : null); break; case 3: setUpdated(value != null ? new DateTime(value, DateTimeZone.UTC).toDateTime() : null); break; case 4: setAccessed(value != null ? new DateTime(value, DateTimeZone.UTC).toDateTime() : null); break; case 5: setId(value.toString()); break; default: throw new org.apache.avro.AvroRuntimeException("Bad index"); } } }
src/main/java/es/redmic/usersettingslib/dto/SettingsBaseDTO.java 0 → 100644 +110 −0 Original line number Diff line number Diff line package es.redmic.usersettingslib.dto; /*- * #%L * user-settings-lib * %% * Copyright (C) 2019 REDMIC Project / Server * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * #L% */ import org.joda.time.DateTime; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import es.redmic.brokerlib.avro.common.CommonDTO; import es.redmic.brokerlib.deserializer.CustomDateTimeDeserializer; import es.redmic.brokerlib.serializer.CustomDateTimeSerializer; public abstract class SettingsBaseDTO extends CommonDTO { public SettingsBaseDTO() { super(); } @JsonSerialize(using = CustomDateTimeSerializer.class) @JsonDeserialize(using = CustomDateTimeDeserializer.class) private DateTime inserted; @JsonSerialize(using = CustomDateTimeSerializer.class) @JsonDeserialize(using = CustomDateTimeDeserializer.class) private DateTime updated; @JsonSerialize(using = CustomDateTimeSerializer.class) @JsonDeserialize(using = CustomDateTimeDeserializer.class) DateTime accessed; public DateTime getInserted() { return inserted; } public void setInserted(DateTime inserted) { this.inserted = inserted; } public DateTime getUpdated() { return updated; } public void setUpdated(DateTime updated) { this.updated = updated; } public DateTime getAccessed() { return accessed; } public void setAccessed(DateTime accessed) { this.accessed = accessed; } @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((accessed == null) ? 0 : accessed.hashCode()); result = prime * result + ((inserted == null) ? 0 : inserted.hashCode()); result = prime * result + ((updated == null) ? 0 : updated.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; SettingsBaseDTO other = (SettingsBaseDTO) obj; if (accessed == null) { if (other.accessed != null) return false; } else if (!accessed.equals(other.accessed)) return false; if (inserted == null) { if (other.inserted != null) return false; } else if (!inserted.equals(other.inserted)) return false; if (updated == null) { if (other.updated != null) return false; } else if (!updated.equals(other.updated)) return false; return true; } }
src/test/java/es/redmic/usersettingslib/unit/dto/SettingsCheckAvroSchemaTest.java→src/test/java/es/redmic/usersettingslib/unit/dto/SaveCheckAvroSchemaTest.java +4 −4 Original line number Diff line number Diff line Loading @@ -27,19 +27,19 @@ import org.junit.Test; import org.skyscreamer.jsonassert.JSONAssert; import es.redmic.testutils.utils.AvroBaseTest; import es.redmic.usersettingslib.dto.SettingsDTO; import es.redmic.usersettingslib.dto.SaveDTO; import es.redmic.usersettingslib.unit.utils.SettingsDataUtil; public class SettingsCheckAvroSchemaTest extends AvroBaseTest { public class SaveCheckAvroSchemaTest extends AvroBaseTest { @Test public void serializeAndDeserialize_IsSuccessful_IfSchemaAndDataAreCorrect() throws JSONException { SettingsDTO dto = SettingsDataUtil.getSettings(); SaveDTO dto = SettingsDataUtil.getSaveDTO(); Object result = serializerAndDeserializer(dto); assertTrue("El objeto obtenido debe ser una instancia de SettingsDTO", SettingsDTO.class.isInstance(result)); assertTrue("El objeto obtenido debe ser una instancia de SaveDTO", SaveDTO.class.isInstance(result)); JSONAssert.assertEquals(result.toString(), dto.toString(), false); } Loading
src/test/java/es/redmic/usersettingslib/unit/dto/SaveCheckDTOValidationTest.java 0 → 100644 +53 −0 Original line number Diff line number Diff line package es.redmic.usersettingslib.unit.dto; /*- * #%L * user-settings-lib * %% * Copyright (C) 2019 REDMIC Project / Server * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * #L% */ import org.junit.Before; import org.junit.Test; import es.redmic.testutils.dto.DTOBaseTest; import es.redmic.usersettingslib.dto.SaveDTO; import es.redmic.usersettingslib.unit.utils.SettingsDataUtil; public class SaveCheckDTOValidationTest extends DTOBaseTest<SaveDTO> { private static SaveDTO dto; @Before public void reset() { dto = SettingsDataUtil.getSaveDTO(); } @Test public void validationDTO_NoReturnError_IfDTOIsCorrect() { checkDTOHasNoError(dto); } @Test public void validationDTO_ReturnError_IfSharedIsNull() { dto.setShared(null); checkDTOHasError(dto, NOT_NULL_MESSAGE_TEMPLATE); } }