Commit 0acbdb4a authored by Noel Alonso's avatar Noel Alonso
Browse files

Merge branch 'release-0.8.0' into 'master'

Actualiza dependencias y adapta código a cambios

See merge request redmic-project/server/library/db!14
parents 2d5ad40d 74204960
Loading
Loading
Loading
Loading
+16 −4
Original line number Diff line number Diff line
@@ -14,15 +14,15 @@
	<groupId>es.redmic.lib</groupId>
	<artifactId>db</artifactId>
	<packaging>jar</packaging>
	<version>0.7.0</version>
	<version>0.8.0</version>
	<name>DB</name>
	<description>Services, repository and models in DB</description>

	<properties>
		<!-- REDMIC -->
		<redmic.db-commons.version>0.6.0</redmic.db-commons.version>
		<redmic.models.version>0.6.1</redmic.models.version>
		<redmic.exceptions.version>0.6.0</redmic.exceptions.version>
		<redmic.db-commons.version>0.7.0</redmic.db-commons.version>
		<redmic.models.version>0.13.0</redmic.models.version>
		<redmic.exceptions.version>0.10.0</redmic.exceptions.version>

		<!-- OTHER -->
		<powermock.version>1.7.3</powermock.version>
@@ -74,6 +74,18 @@
			<artifactId>hibernate-spatial</artifactId>
		</dependency>

		<!-- Logs -->
		<dependency>
			<groupId>org.apache.logging.log4j</groupId>
			<artifactId>log4j-api</artifactId>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>org.apache.logging.log4j</groupId>
			<artifactId>log4j-core</artifactId>
			<scope>provided</scope>
		</dependency>

		<!-- Test -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
+96 −5
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@ package es.redmic.db.administrative.model;
 * #%L
 * DB
 * %%
 * Copyright (C) 2019 REDMIC Project / Server
 * Copyright (C) 2019 - 2021 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.
@@ -20,14 +20,21 @@ package es.redmic.db.administrative.model;
 * #L%
 */

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Cacheable;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

import es.redmic.db.maintenance.administrative.model.ActivityType;
import es.redmic.db.maintenance.administrative.model.ThemeInspire;

/**
 * The persistent class for the activity database table.
@@ -49,10 +56,32 @@ public class Activity extends ActivityBase {
	@JoinColumn(name = "embargoid")
	private Embargo embargo;

	// bi-directional many-to-one association to ThemeInspire
	@ManyToOne
	@JoinColumn(name = "themeinspireid")
	private ThemeInspire themeInspire;

	@Column(name = "activitycategory", length = 2)
	private String activityCategory;

	@Column(length = 5000)
	private String licence;

	@Column(length = 5000)
	private String normative;

	@Column(name = "spatialextension")
	private String spatialExtension;

	@Column
	private Boolean starred;

	// bi-directional many-to-one association to ActivityResource
	@OneToMany(mappedBy = "activity", fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
	private Set<ActivityResource> resources = new HashSet<>();

	public Activity() {
		// Constructor por defecto para que accedan los mappers
	}

	public ActivityType getActivityType() {
@@ -71,6 +100,14 @@ public class Activity extends ActivityBase {
		this.embargo = embargo;
	}

	public ThemeInspire getThemeInspire() {
		return this.themeInspire;
	}

	public void setThemeInspire(ThemeInspire themeInspire) {
		this.themeInspire = themeInspire;
	}

	public String getActivityCategory() {
		return activityCategory;
	}
@@ -78,4 +115,58 @@ public class Activity extends ActivityBase {
	public void setActivityCategory(String activityCategory) {
		this.activityCategory = activityCategory;
	}

	public String getLicence() {
		return this.licence;
	}

	public void setLicence(String licence) {
		this.licence = licence;
	}

	public String getNormative() {
		return this.normative;
	}

	public void setNormative(String normative) {
		this.normative = normative;
	}

	public String getSpatialExtension() {
		return this.spatialExtension;
	}

	public void setSpatialExtension(String spatialExtension) {
		this.spatialExtension = spatialExtension;
	}

	public Set<ActivityResource> getResources() {
		return resources;
	}

	public Boolean getStarred() {
		return this.starred;
	}

	public void setStarred(Boolean starred) {
		this.starred = starred;
	}

	public void setResources(Set<ActivityResource> activityResources) {

		this.resources.clear();

		if (activityResources == null)
			return;

		for (ActivityResource resource: activityResources)
			addResource(resource);
	}

	public ActivityResource addResource(ActivityResource resource) {

		resource.setActivity(this);
		getResources().add(resource);
		return resource;
	}
}
+84 −0
Original line number Diff line number Diff line
package es.redmic.db.atlas.layer.model;
package es.redmic.db.administrative.model;

/*-
 * #%L
 * DB
 * %%
 * Copyright (C) 2019 REDMIC Project / Server
 * Copyright (C) 2019 - 2021 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.
@@ -22,6 +22,7 @@ package es.redmic.db.atlas.layer.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
@@ -29,43 +30,55 @@ import javax.persistence.NamedQuery;
import javax.persistence.Table;

import es.redmic.databaselib.common.model.LongModel;
import es.redmic.db.maintenance.administrative.model.ResourceType;

/**
 * The persistent class for the activityresource database table.
 *
 */
@Entity
@Table(name = "protocols")
@NamedQuery(name = "Protocols.findAll", query = "SELECT p FROM Protocols p")
public class Protocols extends LongModel implements Serializable {
	
@Table(name = "activityresource")
@NamedQuery(name = "ActivityResource.findAll", query = "SELECT a FROM ActivityResource a")
public class ActivityResource extends LongModel implements Serializable {
	private static final long serialVersionUID = 1L;

	private String type;
	
	private String url;
	@ManyToOne
	@JoinColumn(name = "activityid", nullable = false)
	private ActivityBase activity;

	// bi-directional many-to-one association to Rank
	@ManyToOne
	@JoinColumn(name = "servicewmsid", nullable = false)
	private Layer layer;
	@JoinColumn(name = "resourcetypeid", nullable=false)
	private ResourceType resourcetype;

	@Column(name = "urlresource", length = 500)
	private String urlresource;

	public ActivityResource() {
		// Constructor por defecto para que accedan los mappers
	}

	public String getType() {
		return type;
	public ActivityBase getActivity() {
		return this.activity;
	}

	public void setType(String type) {
		this.type = type;
	public void setActivity(ActivityBase activityBase) {
		this.activity = activityBase;
	}

	public String getUrl() {
		return url;
	public ResourceType getResourceType() {
		return this.resourcetype;
	}

	public void setUrl(String url) {
		this.url = url;
	public void setResourceType(ResourceType resourceType) {
		this.resourcetype = resourceType;
	}

	public Layer getLayer() {
		return layer;
	public String getUrlResource() {
		return this.urlresource;
	}

	public void setLayer(Layer layer) {
		this.layer = layer;
	public void setUrlResource(String urlResource) {
		this.urlresource = urlResource;
	}
}
+4 −4
Original line number Diff line number Diff line
package es.redmic.db.geodata.toponym.repository;
package es.redmic.db.administrative.repository;

/*-
 * #%L
 * DB
 * %%
 * Copyright (C) 2019 REDMIC Project / Server
 * Copyright (C) 2019 - 2021 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.
@@ -21,8 +21,8 @@ package es.redmic.db.geodata.toponym.repository;
 */

import es.redmic.databaselib.common.repository.BaseRepository;
import es.redmic.db.geodata.toponym.model.Toponym;
import es.redmic.db.administrative.model.ActivityResource;

public interface ToponymRepository extends BaseRepository<Toponym, Long> {
public interface ActivityResourceRepository extends BaseRepository<ActivityResource, Long> {

}
+0 −80
Original line number Diff line number Diff line
package es.redmic.db.atlas.layer.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 java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import es.redmic.db.atlas.layer.model.Layer;
import es.redmic.models.es.atlas.LatLonBoundingBox;
import es.redmic.models.es.atlas.dto.LayerDTO;
import ma.glasnost.orika.CustomMapper;
import ma.glasnost.orika.MappingContext;

@Component
public class LayerMapper extends CustomMapper<Layer, LayerDTO> {
	
	@Value("${property.URL_LAYERS_MEDIASTORAGE}")
	private String URL_LAYERS;
	
	@Override
	public void mapAtoB(Layer a, LayerDTO b, MappingContext context) {
		
		if (a.getLatLonBoundsImage() != null && a.getLatLonBoundsImage().length > 0) {
			b.setLatLonBoundsImage(getLatLonBoundsImageDTO(a.getLatLonBoundsImage()));
			b.setImage(URL_LAYERS + a.getId() + ".png");
		}
	}

	@Override
	public void mapBtoA(LayerDTO b, Layer a, MappingContext context) {
		
		if (b.getLatLonBoundsImage() != null)
			a.setLatLonBoundsImage(getLatLonBoundsImage(b.getLatLonBoundsImage()));
	}
	
	private Double[] getLatLonBoundsImage(LatLonBoundingBox latLonBoundingBoxDTO) {
		
		List<Double> latLonBoundsImage = new ArrayList<Double>();
		latLonBoundsImage.add(latLonBoundingBoxDTO.getMaxX());
		latLonBoundsImage.add(latLonBoundingBoxDTO.getMaxY());
		latLonBoundsImage.add(latLonBoundingBoxDTO.getMinX());
		latLonBoundsImage.add(latLonBoundingBoxDTO.getMinY());
		return latLonBoundsImage.toArray(new Double[latLonBoundsImage.size()]);
	}
	
	private LatLonBoundingBox getLatLonBoundsImageDTO(Double[] latLonBoundingBox) {
		
		if (latLonBoundingBox == null || latLonBoundingBox.length < 4)
			return null;
		
		LatLonBoundingBox latLonBoundsImageDTO = new LatLonBoundingBox();
		latLonBoundsImageDTO.setMaxX(latLonBoundingBox[0]);
		latLonBoundsImageDTO.setMaxY(latLonBoundingBox[1]);
		latLonBoundsImageDTO.setMinX(latLonBoundingBox[2]);
		latLonBoundsImageDTO.setMinY(latLonBoundingBox[3]);
		
		return latLonBoundsImageDTO;
	}
}
Loading