Loading time-series-lib/src/main/java/es/redmic/timeserieslib/dto/series/SeriesBaseDTO.java 0 → 100644 +85 −0 Original line number Diff line number Diff line package es.redmic.timeserieslib.dto.series; /*- * #%L * Time series library * %% * 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 javax.validation.constraints.NotNull; import org.joda.time.DateTime; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import es.redmic.models.es.common.deserializer.CustomDateTimeDeserializer; import es.redmic.models.es.common.serializer.CustomDateTimeSerializer; public abstract class SeriesBaseDTO extends SeriesCommonDTO { @NotNull private Double value; @NotNull private DateTime date; private Long dataDefinition; protected SeriesBaseDTO() { super(); } public Double getValue() { return value; } public void setValue(Double value) { this.value = value; } @JsonSerialize(using = CustomDateTimeSerializer.class) public DateTime getDate() { return date; } @JsonDeserialize(using = CustomDateTimeDeserializer.class) public void setDate(DateTime date) { this.date = date; } public Long getDataDefinition() { return dataDefinition; } public void setDataDefinition(Long dataDefinition) { this.dataDefinition = dataDefinition; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; return super.equals(obj); } } time-series-lib/src/main/java/es/redmic/timeserieslib/dto/series/SeriesCommonDTO.java 0 → 100644 +100 −0 Original line number Diff line number Diff line package es.redmic.timeserieslib.dto.series; /*- * #%L * Time series library * %% * 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 javax.validation.constraints.Size; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import es.redmic.brokerlib.avro.common.CommonDTO; public abstract class SeriesCommonDTO extends CommonDTO { // Notas @Size(min = 0, max = 1500) private String remark; private Character qFlag = '0'; private Character vFlag = 'U'; protected SeriesCommonDTO() { super(); } public String getRemark() { return remark; } public void setRemark(String remark) { this.remark = remark; } @JsonProperty(value = "qFlag") public Character getQFlag() { return qFlag; } @JsonProperty(value = "qFlag") public void setQFlag(Character qFlag) { if (qFlag != null) this.qFlag = qFlag; } @JsonIgnore public void setqFlag(Character qFlag) { this.qFlag = qFlag; } @JsonProperty(value = "vFlag") public Character getVFlag() { return vFlag; } @JsonProperty(value = "vFlag") public void setVFlag(Character vFlag) { if (vFlag != null) this.vFlag = vFlag; } @JsonIgnore public void setvFlag(Character vFlag) { this.vFlag = vFlag; } // TODO: Añadir @JsonSchemaIgnore private MetaDataDTO _meta = new MetaDataDTO(); @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; return super.equals(obj); } } time-series-lib/src/main/java/es/redmic/timeserieslib/dto/series/TimeSeriesDTO.java +36 −3 Original line number Diff line number Diff line package es.redmic.timeserieslib.dto.series; import com.fasterxml.jackson.annotation.JsonIgnore; import org.apache.avro.Schema; /*- * #%L * Time series library Loading @@ -20,6 +24,35 @@ package es.redmic.timeserieslib.dto.series; * #L% */ public class TimeSeriesDTO { public class TimeSeriesDTO extends SeriesBaseDTO { // @formatter:off @JsonIgnore public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse( "{\"type\":\"record\",\"name\":\"TimeSeriesDTO\",\"namespace\":\"es.redmic.timeserieslib.dto.series\",\"fields\":[]}"); // @formatter:on public TimeSeriesDTO() { super(); } @Override public Schema getSchema() { // TODO Auto-generated method stub return null; } @Override public Object get(int field) { // TODO Auto-generated method stub return null; } @Override public void put(int field, Object value) { // TODO Auto-generated method stub } } time-series-lib/src/test/java/es/redmic/timeserieslib/unit/dto/series/TimSeriesDTOTest.java +32 −2 Original line number Diff line number Diff line Loading @@ -20,12 +20,15 @@ package es.redmic.timeserieslib.unit.dto.series; * #L% */ import org.joda.time.DateTime; import org.junit.Before; import org.junit.Test; import es.redmic.testutils.dto.DTOBaseTest; import es.redmic.timeserieslib.dto.series.TimeSeriesDTO; public class TimSeriesDTOTest extends DTOBaseTest<TimeSeriesDTO> { private static TimeSeriesDTO dto = new TimeSeriesDTO(); Loading @@ -33,6 +36,9 @@ public class TimSeriesDTOTest extends DTOBaseTest<TimeSeriesDTO> { @Before public void reset() { dto.setValue(1.0); dto.setDate(new DateTime()); dto.setRemark("remark"); } @Test Loading @@ -40,4 +46,28 @@ public class TimSeriesDTOTest extends DTOBaseTest<TimeSeriesDTO> { checkDTOHasNoError(dto); } @Test public void validationDTO_ReturnNotNullError_IfValueIsNull() { dto.setValue(null); checkDTOHasError(dto, NOT_NULL_MESSAGE_TEMPLATE); } @Test public void validationDTO_ReturnNotNullError_IfDateIsNull() { dto.setDate(null); checkDTOHasError(dto, NOT_NULL_MESSAGE_TEMPLATE); } @Test public void validationDTO_ReturnSizeError_IfNoteExceedsSize() { dto.setRemark(generateString(1500)); checkDTOHasError(dto, SIZE_MESSAGE_TEMPLATE); } } Loading
time-series-lib/src/main/java/es/redmic/timeserieslib/dto/series/SeriesBaseDTO.java 0 → 100644 +85 −0 Original line number Diff line number Diff line package es.redmic.timeserieslib.dto.series; /*- * #%L * Time series library * %% * 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 javax.validation.constraints.NotNull; import org.joda.time.DateTime; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import es.redmic.models.es.common.deserializer.CustomDateTimeDeserializer; import es.redmic.models.es.common.serializer.CustomDateTimeSerializer; public abstract class SeriesBaseDTO extends SeriesCommonDTO { @NotNull private Double value; @NotNull private DateTime date; private Long dataDefinition; protected SeriesBaseDTO() { super(); } public Double getValue() { return value; } public void setValue(Double value) { this.value = value; } @JsonSerialize(using = CustomDateTimeSerializer.class) public DateTime getDate() { return date; } @JsonDeserialize(using = CustomDateTimeDeserializer.class) public void setDate(DateTime date) { this.date = date; } public Long getDataDefinition() { return dataDefinition; } public void setDataDefinition(Long dataDefinition) { this.dataDefinition = dataDefinition; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; return super.equals(obj); } }
time-series-lib/src/main/java/es/redmic/timeserieslib/dto/series/SeriesCommonDTO.java 0 → 100644 +100 −0 Original line number Diff line number Diff line package es.redmic.timeserieslib.dto.series; /*- * #%L * Time series library * %% * 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 javax.validation.constraints.Size; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import es.redmic.brokerlib.avro.common.CommonDTO; public abstract class SeriesCommonDTO extends CommonDTO { // Notas @Size(min = 0, max = 1500) private String remark; private Character qFlag = '0'; private Character vFlag = 'U'; protected SeriesCommonDTO() { super(); } public String getRemark() { return remark; } public void setRemark(String remark) { this.remark = remark; } @JsonProperty(value = "qFlag") public Character getQFlag() { return qFlag; } @JsonProperty(value = "qFlag") public void setQFlag(Character qFlag) { if (qFlag != null) this.qFlag = qFlag; } @JsonIgnore public void setqFlag(Character qFlag) { this.qFlag = qFlag; } @JsonProperty(value = "vFlag") public Character getVFlag() { return vFlag; } @JsonProperty(value = "vFlag") public void setVFlag(Character vFlag) { if (vFlag != null) this.vFlag = vFlag; } @JsonIgnore public void setvFlag(Character vFlag) { this.vFlag = vFlag; } // TODO: Añadir @JsonSchemaIgnore private MetaDataDTO _meta = new MetaDataDTO(); @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; return super.equals(obj); } }
time-series-lib/src/main/java/es/redmic/timeserieslib/dto/series/TimeSeriesDTO.java +36 −3 Original line number Diff line number Diff line package es.redmic.timeserieslib.dto.series; import com.fasterxml.jackson.annotation.JsonIgnore; import org.apache.avro.Schema; /*- * #%L * Time series library Loading @@ -20,6 +24,35 @@ package es.redmic.timeserieslib.dto.series; * #L% */ public class TimeSeriesDTO { public class TimeSeriesDTO extends SeriesBaseDTO { // @formatter:off @JsonIgnore public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse( "{\"type\":\"record\",\"name\":\"TimeSeriesDTO\",\"namespace\":\"es.redmic.timeserieslib.dto.series\",\"fields\":[]}"); // @formatter:on public TimeSeriesDTO() { super(); } @Override public Schema getSchema() { // TODO Auto-generated method stub return null; } @Override public Object get(int field) { // TODO Auto-generated method stub return null; } @Override public void put(int field, Object value) { // TODO Auto-generated method stub } }
time-series-lib/src/test/java/es/redmic/timeserieslib/unit/dto/series/TimSeriesDTOTest.java +32 −2 Original line number Diff line number Diff line Loading @@ -20,12 +20,15 @@ package es.redmic.timeserieslib.unit.dto.series; * #L% */ import org.joda.time.DateTime; import org.junit.Before; import org.junit.Test; import es.redmic.testutils.dto.DTOBaseTest; import es.redmic.timeserieslib.dto.series.TimeSeriesDTO; public class TimSeriesDTOTest extends DTOBaseTest<TimeSeriesDTO> { private static TimeSeriesDTO dto = new TimeSeriesDTO(); Loading @@ -33,6 +36,9 @@ public class TimSeriesDTOTest extends DTOBaseTest<TimeSeriesDTO> { @Before public void reset() { dto.setValue(1.0); dto.setDate(new DateTime()); dto.setRemark("remark"); } @Test Loading @@ -40,4 +46,28 @@ public class TimSeriesDTOTest extends DTOBaseTest<TimeSeriesDTO> { checkDTOHasNoError(dto); } @Test public void validationDTO_ReturnNotNullError_IfValueIsNull() { dto.setValue(null); checkDTOHasError(dto, NOT_NULL_MESSAGE_TEMPLATE); } @Test public void validationDTO_ReturnNotNullError_IfDateIsNull() { dto.setDate(null); checkDTOHasError(dto, NOT_NULL_MESSAGE_TEMPLATE); } @Test public void validationDTO_ReturnSizeError_IfNoteExceedsSize() { dto.setRemark(generateString(1500)); checkDTOHasError(dto, SIZE_MESSAGE_TEMPLATE); } }