Loading atlas-commands/src/main/java/es/redmic/atlascommands/mapper/ContactMapper.java 0 → 100644 +87 −0 Original line number Diff line number Diff line package es.redmic.atlascommands.mapper; /*- * #%L * Atlas-management * %% * 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.mapstruct.Mapper; import org.opengis.metadata.citation.Address; import org.opengis.metadata.citation.ResponsibleParty; import org.opengis.metadata.citation.Telephone; import es.redmic.atlaslib.dto.layer.ContactDTO; @Mapper public interface ContactMapper { default ContactDTO map(ResponsibleParty contact) { ContactDTO contactDTO = new ContactDTO(); contactDTO.setName(contact.getIndividualName()); if (contact.getOrganisationName() != null) contactDTO.setOrganization(contact.getOrganisationName().toString()); if (contact.getContactInfo() != null) { Telephone phone = contact.getContactInfo().getPhone(); if (phone != null && !phone.getVoices().isEmpty()) contactDTO.setPhone(phone.getVoices().toArray()[0].toString()); if (phone != null && !phone.getFacsimiles().isEmpty()) contactDTO.setFax(phone.getFacsimiles().toArray()[0].toString()); contactDTO.setEmail(getEmail(contact.getContactInfo().getAddress())); contactDTO.setAddress(getAddress(contact.getContactInfo().getAddress())); } if (contact.getPositionName() != null) contactDTO.setContactPosition(contact.getPositionName().toString()); return contactDTO; } default String getEmail(Address address) { if (address == null || address.getElectronicMailAddresses().isEmpty()) return null; return address.getElectronicMailAddresses().toArray()[0].toString(); } default String getAddress(Address address) { if (address == null) return null; String addressAux = null; if (!address.getDeliveryPoints().isEmpty()) addressAux = address.getDeliveryPoints().toArray()[0].toString() + " "; if (address.getCity() != null) addressAux += address.getCity() + " "; if (address.getPostalCode() != null) addressAux += address.getPostalCode() + " "; if (address.getCountry() != null) addressAux += address.getCountry() + " "; return addressAux; } } atlas-commands/src/main/java/es/redmic/atlascommands/mapper/LayerMapper.java 0 → 100644 +232 −0 Original line number Diff line number Diff line package es.redmic.atlascommands.mapper; /*- * #%L * Atlas-management * %% * 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.Arrays; import java.util.List; import org.geotools.data.ows.CRSEnvelope; import org.geotools.data.ows.Layer; import org.geotools.data.ows.StyleImpl; import org.geotools.data.wms.xml.Dimension; import org.geotools.geometry.jts.JTSFactoryFinder; import org.locationtech.jts.geom.Coordinate; import org.locationtech.jts.geom.Polygon; import org.mapstruct.Context; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.Named; import es.redmic.atlaslib.dto.layer.ActivityDTO; import es.redmic.atlaslib.dto.layer.DimensionDTO; import es.redmic.atlaslib.dto.layer.LayerDTO; import es.redmic.atlaslib.dto.layer.StyleLayerDTO; @Mapper public interface LayerMapper { final String SRS = "EPSG:4326"; final int SRID = 4326; final String refRegex = "ref#((\\d*,?)*)#"; final String endLineRegex = "\r?\n|\r"; final String refInBracketsRegex = ".*(" + refRegex + ").*"; final String formatRegex = ".*&format=(\\w*)%2F(\\w*)&.*"; final String host = "atlas.redmic.es"; final String timeDimensionProperty = "time"; final String elevationDimensionProperty = "elevation"; @Mapping(source = "layer", target = "urlSource", qualifiedByName = "urlSource") @Mapping(source = "layer", target = "alias", qualifiedByName = "alias") @Mapping(source = "layer", target = "legend", qualifiedByName = "legend") @Mapping(source = "layer", target = "timeDimension", qualifiedByName = "timeDimension") @Mapping(source = "layer", target = "elevationDimension", qualifiedByName = "elevationDimension") @Mapping(source = "layer", target = "stylesLayer", qualifiedByName = "stylesLayer") @Mapping(source = "layer", target = "abstractLayer", qualifiedByName = "abstractLayer") @Mapping(source = "layer", target = "activities", qualifiedByName = "activities") @Mapping(source = "layer", target = "geometry", qualifiedByName = "geometry") @Mapping(source = "layer", target = "keyword", qualifiedByName = "keyword") LayerDTO map(Layer layer, @Context String urlSource); @Named("urlSource") default String getUrlSource(Layer layer, @Context String urlSource) { return getNormalizedUrl(urlSource); } @Named("alias") default String getAlias(Layer layer, @Context String urlSource) { if (layer.getTitle() != null) return layer.getTitle(); else return layer.getName(); } @Named("legend") default String getLegend(Layer layer, @Context String urlSource) { return ""; } @Named("timeDimension") default DimensionDTO getElevationDimension(Layer layer, @Context String urlSource) { return getDimension(layer, timeDimensionProperty); } @Named("elevationDimension") default DimensionDTO getTimeDimension(Layer layer, @Context String urlSource) { return getDimension(layer, elevationDimensionProperty); } @Named("stylesLayer") default List<StyleLayerDTO> getStyleLayer(Layer layer, @Context String urlSource) { List<StyleLayerDTO> stylesLayer = new ArrayList<>(); for (StyleImpl style : layer.getStyles()) { StyleLayerDTO styleLayerDTO = new StyleLayerDTO(); styleLayerDTO.setName(style.getName()); if (style.getAbstract() != null) { styleLayerDTO.setTitle(style.getAbstract().toString()); styleLayerDTO.setAbstractStyle(style.getAbstract().toString()); } if (style.getLegendURLs() != null && style.getLegendURLs().size() > 0) { String url = getNormalizedUrl(style.getLegendURLs().get(0).toString()); styleLayerDTO.setUrl(url); styleLayerDTO.setFormat(styleLayerDTO.getUrl().replaceAll(formatRegex, "$1/$2")); } stylesLayer.add(styleLayerDTO); } return stylesLayer.isEmpty() ? null : stylesLayer; } @Named("abstractLayer") default String getAbstractLayer(Layer layer, @Context String urlSource) { if (layer.get_abstract() == null) return null; String abstractLayer = layer.get_abstract().replaceAll(endLineRegex, " "); if (abstractLayer.matches(refInBracketsRegex)) { String ref = abstractLayer.replaceAll(refInBracketsRegex, "$1"); if (ref.matches(refRegex)) { abstractLayer = abstractLayer.replace(ref, ""); abstractLayer = abstractLayer.replace(" ", " "); } } return abstractLayer; } @Named("activities") default List<ActivityDTO> getActivities(Layer layer, @Context String urlSource) { if (layer.get_abstract() == null) return null; String abstractLayer = layer.get_abstract().replaceAll(endLineRegex, " "); if (!abstractLayer.matches(refInBracketsRegex)) return null; String ref = abstractLayer.replaceAll(refInBracketsRegex, "$1"); if (!ref.matches(refRegex)) return null; List<ActivityDTO> activities = new ArrayList<>(); String listAct = ref.replaceAll(refRegex, "$1"); String[] listActSplit = listAct.split(","); for (int i = 0; i < listActSplit.length; i++) { ActivityDTO activity = new ActivityDTO(); activity.setId(listActSplit[i]); activities.add(activity); } return activities; } @Named("geometry") default Polygon getGeometry(Layer layer, @Context String urlSource) { if (layer.getBoundingBoxes().get(SRS) == null) return null; CRSEnvelope srsBbox = layer.getBoundingBoxes().get(SRS); Coordinate[] coordinates = new Coordinate[] { new Coordinate(srsBbox.getMinY(), srsBbox.getMinX()), new Coordinate(srsBbox.getMinY(), srsBbox.getMaxX()), new Coordinate(srsBbox.getMaxY(), srsBbox.getMaxX()), new Coordinate(srsBbox.getMaxY(), srsBbox.getMinX()), new Coordinate(srsBbox.getMinY(), srsBbox.getMinX()) }; Polygon polygon = JTSFactoryFinder.getGeometryFactory().createPolygon(coordinates); polygon.setSRID(SRID); return polygon; } @Named("keyword") default List<String> getKeyword(Layer layer, @Context String urlSource) { if (layer.getKeywords() == null) return null; return Arrays.asList(layer.getKeywords()); } default String getNormalizedUrl(String url) { if (url != null && url.contains(host)) { url.replaceFirst("http:", "https:").replaceFirst(":80", ""); } return url; } default DimensionDTO getDimension(Layer layer, String property) { if (layer.getDimensions() == null || layer.getDimensions().size() == 0) return null; DimensionDTO dimension = new DimensionDTO(); Dimension source = layer.getDimension(property); dimension.setName(source.getName()); dimension.setUnits(source.getUnits()); dimension.setDefaultValue(source.getExtent().getDefaultValue()); return dimension; } } Loading
atlas-commands/src/main/java/es/redmic/atlascommands/mapper/ContactMapper.java 0 → 100644 +87 −0 Original line number Diff line number Diff line package es.redmic.atlascommands.mapper; /*- * #%L * Atlas-management * %% * 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.mapstruct.Mapper; import org.opengis.metadata.citation.Address; import org.opengis.metadata.citation.ResponsibleParty; import org.opengis.metadata.citation.Telephone; import es.redmic.atlaslib.dto.layer.ContactDTO; @Mapper public interface ContactMapper { default ContactDTO map(ResponsibleParty contact) { ContactDTO contactDTO = new ContactDTO(); contactDTO.setName(contact.getIndividualName()); if (contact.getOrganisationName() != null) contactDTO.setOrganization(contact.getOrganisationName().toString()); if (contact.getContactInfo() != null) { Telephone phone = contact.getContactInfo().getPhone(); if (phone != null && !phone.getVoices().isEmpty()) contactDTO.setPhone(phone.getVoices().toArray()[0].toString()); if (phone != null && !phone.getFacsimiles().isEmpty()) contactDTO.setFax(phone.getFacsimiles().toArray()[0].toString()); contactDTO.setEmail(getEmail(contact.getContactInfo().getAddress())); contactDTO.setAddress(getAddress(contact.getContactInfo().getAddress())); } if (contact.getPositionName() != null) contactDTO.setContactPosition(contact.getPositionName().toString()); return contactDTO; } default String getEmail(Address address) { if (address == null || address.getElectronicMailAddresses().isEmpty()) return null; return address.getElectronicMailAddresses().toArray()[0].toString(); } default String getAddress(Address address) { if (address == null) return null; String addressAux = null; if (!address.getDeliveryPoints().isEmpty()) addressAux = address.getDeliveryPoints().toArray()[0].toString() + " "; if (address.getCity() != null) addressAux += address.getCity() + " "; if (address.getPostalCode() != null) addressAux += address.getPostalCode() + " "; if (address.getCountry() != null) addressAux += address.getCountry() + " "; return addressAux; } }
atlas-commands/src/main/java/es/redmic/atlascommands/mapper/LayerMapper.java 0 → 100644 +232 −0 Original line number Diff line number Diff line package es.redmic.atlascommands.mapper; /*- * #%L * Atlas-management * %% * 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.Arrays; import java.util.List; import org.geotools.data.ows.CRSEnvelope; import org.geotools.data.ows.Layer; import org.geotools.data.ows.StyleImpl; import org.geotools.data.wms.xml.Dimension; import org.geotools.geometry.jts.JTSFactoryFinder; import org.locationtech.jts.geom.Coordinate; import org.locationtech.jts.geom.Polygon; import org.mapstruct.Context; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.Named; import es.redmic.atlaslib.dto.layer.ActivityDTO; import es.redmic.atlaslib.dto.layer.DimensionDTO; import es.redmic.atlaslib.dto.layer.LayerDTO; import es.redmic.atlaslib.dto.layer.StyleLayerDTO; @Mapper public interface LayerMapper { final String SRS = "EPSG:4326"; final int SRID = 4326; final String refRegex = "ref#((\\d*,?)*)#"; final String endLineRegex = "\r?\n|\r"; final String refInBracketsRegex = ".*(" + refRegex + ").*"; final String formatRegex = ".*&format=(\\w*)%2F(\\w*)&.*"; final String host = "atlas.redmic.es"; final String timeDimensionProperty = "time"; final String elevationDimensionProperty = "elevation"; @Mapping(source = "layer", target = "urlSource", qualifiedByName = "urlSource") @Mapping(source = "layer", target = "alias", qualifiedByName = "alias") @Mapping(source = "layer", target = "legend", qualifiedByName = "legend") @Mapping(source = "layer", target = "timeDimension", qualifiedByName = "timeDimension") @Mapping(source = "layer", target = "elevationDimension", qualifiedByName = "elevationDimension") @Mapping(source = "layer", target = "stylesLayer", qualifiedByName = "stylesLayer") @Mapping(source = "layer", target = "abstractLayer", qualifiedByName = "abstractLayer") @Mapping(source = "layer", target = "activities", qualifiedByName = "activities") @Mapping(source = "layer", target = "geometry", qualifiedByName = "geometry") @Mapping(source = "layer", target = "keyword", qualifiedByName = "keyword") LayerDTO map(Layer layer, @Context String urlSource); @Named("urlSource") default String getUrlSource(Layer layer, @Context String urlSource) { return getNormalizedUrl(urlSource); } @Named("alias") default String getAlias(Layer layer, @Context String urlSource) { if (layer.getTitle() != null) return layer.getTitle(); else return layer.getName(); } @Named("legend") default String getLegend(Layer layer, @Context String urlSource) { return ""; } @Named("timeDimension") default DimensionDTO getElevationDimension(Layer layer, @Context String urlSource) { return getDimension(layer, timeDimensionProperty); } @Named("elevationDimension") default DimensionDTO getTimeDimension(Layer layer, @Context String urlSource) { return getDimension(layer, elevationDimensionProperty); } @Named("stylesLayer") default List<StyleLayerDTO> getStyleLayer(Layer layer, @Context String urlSource) { List<StyleLayerDTO> stylesLayer = new ArrayList<>(); for (StyleImpl style : layer.getStyles()) { StyleLayerDTO styleLayerDTO = new StyleLayerDTO(); styleLayerDTO.setName(style.getName()); if (style.getAbstract() != null) { styleLayerDTO.setTitle(style.getAbstract().toString()); styleLayerDTO.setAbstractStyle(style.getAbstract().toString()); } if (style.getLegendURLs() != null && style.getLegendURLs().size() > 0) { String url = getNormalizedUrl(style.getLegendURLs().get(0).toString()); styleLayerDTO.setUrl(url); styleLayerDTO.setFormat(styleLayerDTO.getUrl().replaceAll(formatRegex, "$1/$2")); } stylesLayer.add(styleLayerDTO); } return stylesLayer.isEmpty() ? null : stylesLayer; } @Named("abstractLayer") default String getAbstractLayer(Layer layer, @Context String urlSource) { if (layer.get_abstract() == null) return null; String abstractLayer = layer.get_abstract().replaceAll(endLineRegex, " "); if (abstractLayer.matches(refInBracketsRegex)) { String ref = abstractLayer.replaceAll(refInBracketsRegex, "$1"); if (ref.matches(refRegex)) { abstractLayer = abstractLayer.replace(ref, ""); abstractLayer = abstractLayer.replace(" ", " "); } } return abstractLayer; } @Named("activities") default List<ActivityDTO> getActivities(Layer layer, @Context String urlSource) { if (layer.get_abstract() == null) return null; String abstractLayer = layer.get_abstract().replaceAll(endLineRegex, " "); if (!abstractLayer.matches(refInBracketsRegex)) return null; String ref = abstractLayer.replaceAll(refInBracketsRegex, "$1"); if (!ref.matches(refRegex)) return null; List<ActivityDTO> activities = new ArrayList<>(); String listAct = ref.replaceAll(refRegex, "$1"); String[] listActSplit = listAct.split(","); for (int i = 0; i < listActSplit.length; i++) { ActivityDTO activity = new ActivityDTO(); activity.setId(listActSplit[i]); activities.add(activity); } return activities; } @Named("geometry") default Polygon getGeometry(Layer layer, @Context String urlSource) { if (layer.getBoundingBoxes().get(SRS) == null) return null; CRSEnvelope srsBbox = layer.getBoundingBoxes().get(SRS); Coordinate[] coordinates = new Coordinate[] { new Coordinate(srsBbox.getMinY(), srsBbox.getMinX()), new Coordinate(srsBbox.getMinY(), srsBbox.getMaxX()), new Coordinate(srsBbox.getMaxY(), srsBbox.getMaxX()), new Coordinate(srsBbox.getMaxY(), srsBbox.getMinX()), new Coordinate(srsBbox.getMinY(), srsBbox.getMinX()) }; Polygon polygon = JTSFactoryFinder.getGeometryFactory().createPolygon(coordinates); polygon.setSRID(SRID); return polygon; } @Named("keyword") default List<String> getKeyword(Layer layer, @Context String urlSource) { if (layer.getKeywords() == null) return null; return Arrays.asList(layer.getKeywords()); } default String getNormalizedUrl(String url) { if (url != null && url.contains(host)) { url.replaceFirst("http:", "https:").replaceFirst(":80", ""); } return url; } default DimensionDTO getDimension(Layer layer, String property) { if (layer.getDimensions() == null || layer.getDimensions().size() == 0) return null; DimensionDTO dimension = new DimensionDTO(); Dimension source = layer.getDimension(property); dimension.setName(source.getName()); dimension.setUnits(source.getUnits()); dimension.setDefaultValue(source.getExtent().getDefaultValue()); return dimension; } }