Commit 9b0a5877 authored by Noel Alonso's avatar Noel Alonso
Browse files

Elimina componentes de timeseries

parent e702a44e
Loading
Loading
Loading
Loading
+0 −64
Original line number Diff line number Diff line
package es.redmic.db.series.timeseries.mapper;

/*-
 * #%L
 * DB
 * %%
 * 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.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import es.redmic.db.geodata.properties.fixedsurvey.model.FixedMeasurement;
import es.redmic.db.geodata.properties.fixedsurvey.repository.FixedMeasurementRepository;
import es.redmic.db.maintenance.parameter.model.DataDefinition;
import es.redmic.db.series.common.mapper.SeriesBaseMapper;
import es.redmic.db.series.timeseries.model.TimeSeries;
import es.redmic.models.es.series.timeseries.dto.TimeSeriesDTO;
import ma.glasnost.orika.MappingContext;

@Component
public class TimeSeriesMapper extends SeriesBaseMapper<TimeSeries, TimeSeriesDTO> {

	@Autowired
	FixedMeasurementRepository measurementRepository;

	@Override
	public void mapAtoB(TimeSeries a, TimeSeriesDTO b, MappingContext context) {

		super.mapAtoB(a, b, context);
		b.setDataDefinition(a.getFixedMeasurement().getDataDefinition().getId());

		b.set_grandparentId(a.getFixedMeasurement().getFixedSurvey().getActivity().getId().toString());
		b.set_parentId(a.getFixedMeasurement().getFixedSurvey().getUuid());
	}

	@Override
	public void mapBtoA(TimeSeriesDTO a, TimeSeries b, MappingContext context) {

		super.mapBtoA(a, b, context);
		b.setFixedMeasurement(getMeasurement(a.getDataDefinition()));
	}

	private FixedMeasurement getMeasurement(Long dataDefinitionId) {

		DataDefinition dataDefinition = new DataDefinition();
		dataDefinition.setId(dataDefinitionId);

		return measurementRepository.findByDataDefinition(dataDefinition);
	}
}
+0 −106
Original line number Diff line number Diff line
package es.redmic.db.series.timeseries.model;

/*-
 * #%L
 * DB
 * %%
 * 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.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Type;
import org.joda.time.DateTime;

import es.redmic.db.geodata.properties.fixedsurvey.model.FixedMeasurement;
import es.redmic.db.series.common.model.SeriesBase;

/**
 * The persistent class for the timeseries database table.
 * 
 */
@Entity
@Table(name = "timeseries")
@NamedQuery(name = "TimeSeries.findAll", query = "SELECT t FROM TimeSeries t")
public class TimeSeries extends SeriesBase implements Serializable {
	private static final long serialVersionUID = 1L;

	private double z;

	@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime", parameters = {
			@Parameter(name = "databaseZone", value = "jvm"), @Parameter(name = "javaZone", value = "jvm") })
	@Column(nullable = false)
	private DateTime date;

	@Column(length = 1500)
	private String remark;

	@Column(nullable = false)
	private double value;

	// bi-directional many-to-one association to Measurement
	@ManyToOne
	@JoinColumn(name = "measurementid", nullable = false)
	private FixedMeasurement fixedMeasurement;

	public double getZ() {
		return this.z;
	}

	public void setZ(double z) {
		this.z = z;
	}

	public DateTime getDate() {
		return this.date;
	}

	public void setDate(DateTime date) {
		this.date = date;
	}

	public String getRemark() {
		return this.remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public double getValue() {
		return this.value;
	}

	public void setValue(double value) {
		this.value = value;
	}

	public FixedMeasurement getFixedMeasurement() {
		return fixedMeasurement;
	}

	public void setFixedMeasurement(FixedMeasurement fixedMeasurement) {
		this.fixedMeasurement = fixedMeasurement;
	}
}
+0 −35
Original line number Diff line number Diff line
package es.redmic.db.series.timeseries.repository;

/*-
 * #%L
 * DB
 * %%
 * 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.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import es.redmic.databaselib.common.repository.BaseRepository;
import es.redmic.db.series.timeseries.model.TimeSeries;

public interface TimeSeriesRepository extends BaseRepository<TimeSeries, Long> {
	
	@Query(value = "SELECT t FROM TimeSeries t WHERE t.id between :start and :end")
	Page<TimeSeries> findBetween(@Param("start") long start, @Param("end") long end, Pageable pageable);
}
+0 −49
Original line number Diff line number Diff line
package es.redmic.db.series.timeseries.service;

/*-
 * #%L
 * DB
 * %%
 * 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.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import es.redmic.db.geodata.properties.fixedsurvey.model.FixedMeasurement;
import es.redmic.db.series.common.service.RWBaseSeriesService;
import es.redmic.db.series.timeseries.model.TimeSeries;
import es.redmic.db.series.timeseries.repository.TimeSeriesRepository;
import es.redmic.models.es.series.timeseries.dto.TimeSeriesDTO;

@Service
public class TimeSeriesService extends RWBaseSeriesService<TimeSeries, TimeSeriesDTO> {
	
	@Autowired
	public TimeSeriesService(TimeSeriesRepository repository) {
		super(repository);
	}
	
	protected TimeSeries setFixedMeasurement(TimeSeries model, FixedMeasurement stationMeasurement) {
		model.setFixedMeasurement(stationMeasurement);
		return model;
	}

	@Override
	protected TimeSeries setReferences(TimeSeries model, TimeSeriesDTO dto) {
		return model;
	}
}