Skip to content

Commit

Permalink
Add baseMap index information on server side
Browse files Browse the repository at this point in the history
This link to #436
  • Loading branch information
pierre committed Dec 3, 2018
1 parent 9157c03 commit f0e79a3
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
import java.util.stream.Collectors;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
Expand Down Expand Up @@ -42,5 +45,25 @@ protected void processProperties(ConfigurableListableBeanFactory beanFactory, Pr
public static String getProperty(String name) {
return propertiesMap.get(name);
}


/**
* Get Map of values where key like given regex
*
* @param regexkey
* @return all value where key like regexKey, null if no key matches
*/
public static Map<Integer, String> getPropertiesLike(String regexKey){

Map<Integer, String> result = new HashMap<Integer, String>();
int index = 0;
for (Entry<String, String> entry : propertiesMap.entrySet()) {

if (entry.getKey().matches(regexKey)) {
result.put(index, entry.getValue());
index++;
}
}
return result;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class BordereauParcellaire {
private List<String> fieldSearch;

private boolean isEmpty;

private int baseMapIndex;



Expand Down Expand Up @@ -175,5 +177,20 @@ public Style getStyle() {
public void setStyle(Style style) {
this.style = style;
}

/**
* @return the baseMapIndex
*/
public int getBaseMapIndex() {
return baseMapIndex;
}

@XmlElement
/**
* @param baseMapIndex the baseMapIndex to set
*/
public void setBaseMapIndex(int baseMapIndex) {
this.baseMapIndex = baseMapIndex;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ public Map<String, Object> getConfiguration(){
configuration.put("dateValiditeMajic", CadastrappPlaceHolder.getProperty("pdf.dateValiditeDonneesMajic"));
configuration.put("dateValiditeEDIGEO", CadastrappPlaceHolder.getProperty("pdf.dateValiditeDonneesEDIGEO"));

configuration.put("pdfbasemaptitle0", CadastrappPlaceHolder.getProperty("pdf.baseMap.0.title"));
configuration.put("pdfbasemaptitle1", CadastrappPlaceHolder.getProperty("pdf.baseMap.1.title"));
// Add base map hashmap to let user choose for BP
final String regexBaseMap = "^pdf\\.baseMap\\.[0-9]*\\.title$";
configuration.put("pdfbasemaptitles", CadastrappPlaceHolder.getPropertiesLike(regexBaseMap));

return configuration;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,26 +322,27 @@ public Response createImageBordereauParcellaire(@QueryParam("parcelle") String p

Graphics2D g2 = finalImage.createGraphics();

// test if current baseMapIndex exist baseMapIndex;
final String propNamePrefixBaseMap = "pdf.baseMap."+baseMapIndex+".";
final String propNamebaseMapWMSUrl = propNamePrefixBaseMap+"wms.url";
// test if current baseMapIndex exist;
StringBuilder prefixPropNameSB = new StringBuilder();
String prefixPropName = prefixPropNameSB.append("pdf.baseMap.").append(baseMapIndex).append(".").toString();

// Add basemap only if parameter is defined
final String baseMapWMSUrl = CadastrappPlaceHolder.getProperty(propNamebaseMapWMSUrl);
final String baseMapWMSUrl = CadastrappPlaceHolder.getProperty(prefixPropName.concat("wms.url"));

if (baseMapWMSUrl != null && baseMapWMSUrl.length() > 1) {
// Get basemap image with good BBOX
try {
logger.debug("WMS call for basemap with URL : " + baseMapWMSUrl);

// Add basic authent parameter if not empty
final String baseMapWMSUsername = CadastrappPlaceHolder.getProperty("propNamePrefixBaseMap"+"wms.username");
final String baseMapWMSPassword = CadastrappPlaceHolder.getProperty("propNamePrefixBaseMap"+"wms.password");
final String baseMapWMSUsername = CadastrappPlaceHolder.getProperty(prefixPropName.concat("wms.username"));
final String baseMapWMSPassword = CadastrappPlaceHolder.getProperty(prefixPropName.concat("wms.password"));

WebMapServer wms = createWebMapServer(baseMapWMSUrl,baseMapWMSUsername, baseMapWMSPassword );

final String baseMapLayerName = CadastrappPlaceHolder.getProperty("propNamePrefixBaseMap"+"layer.name");
final String baseMapFormat = CadastrappPlaceHolder.getProperty("propNamePrefixBaseMap"+"format");
final String baseMapSRS = CadastrappPlaceHolder.getProperty("propNamePrefixBaseMap"+"SRS");
final String baseMapLayerName = CadastrappPlaceHolder.getProperty(prefixPropName.concat("layer.name"));
final String baseMapFormat = CadastrappPlaceHolder.getProperty(prefixPropName.concat("format"));
final String baseMapSRS = CadastrappPlaceHolder.getProperty(prefixPropName.concat("SRS"));

GetMapRequest request = createAndConfigureMapRequest(wms, baseMapFormat, baseMapLayerName, pdfImagePixelSize, baseMapSRS, bounds);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public class BordereauParcellaireController extends CadController {
public Response createBordereauParcellaire(@Context HttpHeaders headers,
@QueryParam("parcelle") final List<String> parcelleList,
@DefaultValue("0") @QueryParam("personaldata") int personalData,
@DefaultValue("0") @QueryParam("basemapindex") int baseMapIndex,
@DefaultValue("#1446DE") @QueryParam("fillcolor") String styleFillColor,
@DefaultValue("0.50") @QueryParam("opacity") float styleFillOpacity,
@DefaultValue("#10259E") @QueryParam("strokecolor") String styleStrokeColor,
Expand Down Expand Up @@ -146,7 +147,7 @@ public Response createBordereauParcellaire(@Context HttpHeaders headers,
plotsStyle.setStrokeWidth(styleStrokeWidth);

// Get bordereau parcellaire information
BordereauParcellaire bordereauParcellaire = bordereauParcellaireHelper.getBordereauParcellaireInformation(newParcelleList, personalData, headers, false, plotsStyle);
BordereauParcellaire bordereauParcellaire = bordereauParcellaireHelper.getBordereauParcellaireInformation(newParcelleList, personalData, headers, false, plotsStyle, baseMapIndex);
File xmlfile = null;
File foFile = null;
OutputStream foOutPutStream = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,23 @@ public final class BordereauParcellaireHelper extends CadController{

final String tableProprietaire = "proprietaire_parcelle";
final String tableCoProprietaire = "co_propriete_parcelle";

/**
* Get all information from database for all parcelle list
*
* @param headers use for CNIL level limitation
* @param isCoPro get copro BP information if true
* @param parcelleList
* List of parcelle id, like
* @param personalData
* filter use to add owners information about parcelle, 1 to get
* owner information
*
* @return BordereauParcellaire witch contains list of parcelle
*/
public BordereauParcellaire getBordereauParcellaireInformation(List<String> parcelleList, int personalData, HttpHeaders headers, boolean isCoPro) {
return getBordereauParcellaireInformation(parcelleList, personalData, headers, isCoPro, null, 0);
}

/**
* Get all information from database for all parcelle list
Expand All @@ -67,10 +84,12 @@ public final class BordereauParcellaireHelper extends CadController{
* @param personalData
* filter use to add owners information about parcelle, 1 to get
* owner information
* @param plotStyle style to display plot on image
* @param baseMapIndex index number of wanted basemap
*
* @return BordereauParcellaire witch contains list of parcelle
*/
public BordereauParcellaire getBordereauParcellaireInformation(List<String> parcelleList, int personalData, HttpHeaders headers, boolean isCoPro, Style plotStyle) {
public BordereauParcellaire getBordereauParcellaireInformation(List<String> parcelleList, int personalData, HttpHeaders headers, boolean isCoPro, Style plotStyle, int baseMapIndex) {


BordereauParcellaire bordereauParcellaire = new BordereauParcellaire();
Expand All @@ -89,6 +108,7 @@ public BordereauParcellaire getBordereauParcellaireInformation(List<String> parc
bordereauParcellaire.setService(organisme);
bordereauParcellaire.setServiceUrl(webappUrl);
bordereauParcellaire.setStyle(plotStyle);
bordereauParcellaire.setBaseMapIndex(baseMapIndex);

List<Parcelle> parcellesInformation = new ArrayList<Parcelle>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ private File createBordereauParcellaireById(String parcelle, HttpHeaders headers
parcellId.add(parcelle);

// Get bordereau parcellaire information
BordereauParcellaire bordereauParcellaire = bordereauParcellaireHelper.getBordereauParcellaireInformation(parcellId, 1, headers,false, null);
BordereauParcellaire bordereauParcellaire = bordereauParcellaireHelper.getBordereauParcellaireInformation(parcellId, 1, headers,false);

File pdf = null;
try {
Expand Down Expand Up @@ -326,7 +326,7 @@ private File createBordereauParcellaireByCC(String comptecommunal,String parcell
}

// Get bordereau parcellaire information
BordereauParcellaire bordereauParcellaire = bordereauParcellaireHelper.getBordereauParcellaireInformation(parcellesId, 1, headers, isCoPro, null);
BordereauParcellaire bordereauParcellaire = bordereauParcellaireHelper.getBordereauParcellaireInformation(parcellesId, 1, headers, isCoPro);
try {
//generate PDF
if(bordereauParcellaire.isEmpty()){
Expand Down Expand Up @@ -408,7 +408,7 @@ private File createBordereauParcellaireByInfoParcelle(String commune, String sec

}
// Get bordereau parcellaire information
BordereauParcellaire bordereauParcellaire = bordereauParcellaireHelper.getBordereauParcellaireInformation(parcellId, 1, headers,false, null);
BordereauParcellaire bordereauParcellaire = bordereauParcellaireHelper.getBordereauParcellaireInformation(parcellId, 1, headers,false);
File pdf = null;
try {
//generate PDF
Expand Down Expand Up @@ -481,7 +481,7 @@ private File createBordereauParcellaireByInfoOwner(String commune, String ownerN

}
// Get bordereau parcellaire information
BordereauParcellaire bordereauParcellaire = bordereauParcellaireHelper.getBordereauParcellaireInformation(parcellId, 1, headers,false, null);
BordereauParcellaire bordereauParcellaire = bordereauParcellaireHelper.getBordereauParcellaireInformation(parcellId, 1, headers,false);
File pdf = null;
try {
//generate PDF
Expand Down Expand Up @@ -553,7 +553,7 @@ private File createBordereauParcellaireLot(String commune, String section, Strin

}
// Get bordereau parcellaire information
BordereauParcellaire bordereauParcellaire = bordereauParcellaireHelper.getBordereauParcellaireInformation(parcellId, 1, headers,false, null);
BordereauParcellaire bordereauParcellaire = bordereauParcellaireHelper.getBordereauParcellaireInformation(parcellId, 1, headers, false);

File pdf = null;
try {
Expand Down
10 changes: 6 additions & 4 deletions cadastrapp/src/main/resources/cadastrapp.properties
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,16 @@ pdf.ratio.mediumScale=0.2
pdf.ratio.bigScale=0.1

############################################################
## In this section you can add two differents basemaps
## In this section you can add as many differents basemaps you want
## keep the same syntax for keys values pdf.baseMap.index.
##
## those basemaps will only be used to create image for pdf on server side
## if several basemaps are set, the end user will be able to chose the one he wants
## if only one basemap is set, end user won't have the choose
## if only one basemap is set, end user won't have the choise
## and if no baseMap URL are set then no basemap image will be added in pdf

# BaseMap Title to be display in user interface
pdf.baseMap.0.title="OSM Google Style - geobretagne"
pdf.baseMap.0.title=OSM Google Style - geobretagne
pdf.baseMap.0.wms.url=http://osm.geobretagne.fr/service/wms?VERSION=1.1.1&Request=GetCapabilities&Service=WMS
pdf.baseMap.0.layer.name=osm:google
pdf.baseMap.0.format=image/png
Expand All @@ -62,7 +64,7 @@ pdf.baseMap.0.wms.username=
pdf.baseMap.0.wms.password=

# BaseMap Title to be display in user interface
pdf.baseMap.1.title="OSM Map Style - geobretagne"
pdf.baseMap.1.title=OSM Map Style - geobretagne
pdf.baseMap.1.wms.url=http://osm.geobretagne.fr/service/wms?VERSION=1.1.1&Request=GetCapabilities&Service=WMS
pdf.baseMap.1.layer.name=osm:map
pdf.baseMap.1.format=image/png
Expand Down
5 changes: 4 additions & 1 deletion cadastrapp/src/main/resources/xsl/bordereauParcellaire.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@
<xsl:variable name="strokeWidth">
<xsl:value-of select="style/@strokeWidth" />
</xsl:variable>
<xsl:variable name="baseMapIndex">
<xsl:value-of select="baseMapIndex" />
</xsl:variable>

<xsl:for-each select="parcelles/parcelle">
<fo:table table-layout="fixed" page-break-before="always">
Expand All @@ -97,7 +100,7 @@
<xsl:choose>
<!-- with given style -->
<xsl:when test="$fillColor">
<xsl:value-of select="$serviceUrl" />/getImageBordereau?parcelle=<xsl:value-of select="@parcelleId" /><![CDATA[&]]>fillcolor=<xsl:value-of select="$fillColor" /><![CDATA[&]]>fillopacity=<xsl:value-of select="$fillOpacity" /><![CDATA[&]]>strokecolor=<xsl:value-of select="$strokeColor" /><![CDATA[&]]>strokewidth=<xsl:value-of select="$strokeWidth" />
<xsl:value-of select="$serviceUrl" />/getImageBordereau?parcelle=<xsl:value-of select="@parcelleId" /><![CDATA[&]]>fillcolor=<xsl:value-of select="$fillColor" /><![CDATA[&]]>fillopacity=<xsl:value-of select="$fillOpacity" /><![CDATA[&]]>strokecolor=<xsl:value-of select="$strokeColor" /><![CDATA[&]]>strokewidth=<xsl:value-of select="$strokeWidth" /><![CDATA[&]]>basemapindex=<xsl:value-of select="$baseMapIndex" />
</xsl:when>
<!-- without style -->
<xsl:otherwise>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void testCreateImageBordereauParcellaire() {

ImageParcelleController imageParcelleController = new ImageParcelleController();

Response response = imageParcelleController.createImageBordereauParcellaire("2014630103000AO0351", "#1446DE", (float) 0.50, "#10259E",2);
Response response = imageParcelleController.createImageBordereauParcellaire("2014630103000AO0351", 0, "#1446DE", (float) 0.50, "#10259E",2);


}
Expand Down

0 comments on commit f0e79a3

Please sign in to comment.