Skip to content

Commit

Permalink
Merge pull request #1167 from fgravin/customExtract
Browse files Browse the repository at this point in the history
Make some ui elements more customisable
  • Loading branch information
fgravin committed Sep 1, 2015
2 parents 8ebd377 + 5ffed8c commit 679d21b
Show file tree
Hide file tree
Showing 12 changed files with 272 additions and 244 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,159 +29,160 @@
//
package org.fao.geonet.services.metadata;

import jeeves.interfaces.Service;
import jeeves.server.ServiceConfig;
import jeeves.server.UserSession;
import jeeves.server.context.ServiceContext;
import org.fao.geonet.Util;
import org.fao.geonet.GeonetContext;
import org.fao.geonet.constants.Geonet;
import jeeves.server.dispatchers.ServiceManager;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.fao.geonet.ApplicationContextHolder;
import org.fao.geonet.kernel.DataManager;
import org.fao.geonet.kernel.SelectionManager;
import org.jdom.Element;
import org.jdom.xpath.XPath;

import java.nio.file.Path;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.NativeWebRequest;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

//=============================================================================

public class ExtractServicesLayers implements Service {
//--------------------------------------------------------------------------
//---
//--- Init
//---
//--------------------------------------------------------------------------

public void init(Path appPath, ServiceConfig params) throws Exception {}

//--------------------------------------------------------------------------
//---
//--- Service
//---
//--------------------------------------------------------------------------
@Controller
public class ExtractServicesLayers {

public Element exec(Element params, ServiceContext context) throws Exception {
@RequestMapping(value = "/{lang}/selection.layers")
@ResponseBody
public JSONObject getLayersFromSelectedMetadatas(
@PathVariable String lang,
@RequestParam(value = "id", required = false) String paramId,
final NativeWebRequest webRequest) throws Exception {

GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
final ServiceManager serviceManager = ApplicationContextHolder.get().getBean(ServiceManager.class);
ServiceContext context = serviceManager.createServiceContext("selection.layers", lang, webRequest.getNativeRequest(HttpServletRequest.class));

DataManager dm = gc.getBean(DataManager.class);
UserSession us = context.getUserSession();
DataManager dm = context.getBean(DataManager.class);
UserSession us = context.getUserSession();
SelectionManager sm = SelectionManager.getManager(us);

JSONObject ret = new JSONObject();
JSONArray services = new JSONArray();
JSONArray layers = new JSONArray();

context.info("Get selected metadata");
SelectionManager sm = SelectionManager.getManager(us);
ArrayList<String> lst = new ArrayList<String>();

Element ret = new Element("response");

String paramId = Util.getParam(params, "id", null) ;
ArrayList<String> lst = new ArrayList<String>();

// case #1 : #id parameter is undefined
if (paramId == null) {
synchronized(sm.getSelection("metadata")) {
for (Iterator<String> iter = sm.getSelection("metadata").iterator(); iter.hasNext();) {
String uuid = (String) iter.next();
String id = dm.getMetadataId(uuid);
lst.add(id);
}
}
} else { // case #2 : id parameter has been passed
lst.add(paramId);
}

// case #1 : #id parameter is undefined
if (paramId == null) {
synchronized(sm.getSelection("metadata")) {
for (Iterator<String> iter = sm.getSelection("metadata").iterator(); iter.hasNext();) {
String uuid = (String) iter.next();
String id = dm.getMetadataId(uuid);
lst.add(id);
}
}
} else { // case #2 : id parameter has been passed
lst.add(paramId);
}

for (Iterator<String> iter = lst.iterator(); iter.hasNext();) {
String id = iter.next();
for (Iterator<String> iter = lst.iterator(); iter.hasNext();) {
String id = iter.next();
String uuid = dm.getMetadataUuid(id);

Element curMd = dm.getMetadata(context, id, false, false, false);
Element curMd = dm.getMetadata(context, id, false, false, false);

XPath xpath = XPath.newInstance("gmd:distributionInfo/gmd:MD_Distribution/gmd:transferOptions/gmd:MD_DigitalTransferOptions/gmd:onLine");
XPath xpath = XPath.newInstance("gmd:distributionInfo/gmd:MD_Distribution/gmd:transferOptions/gmd:MD_DigitalTransferOptions/gmd:onLine");

List<Element> elems ;
List<Element> elems ;

try {
@SuppressWarnings("unchecked")
try {
@SuppressWarnings("unchecked")
List<Element> tmp = xpath.selectNodes(curMd);
elems = tmp;
} catch (Exception e) {
// Bad XML input ?
continue;
}

for (Element curnode : elems) {
XPath pLinkage = XPath.newInstance("gmd:CI_OnlineResource/gmd:linkage/gmd:URL");
XPath pProtocol = XPath.newInstance("gmd:CI_OnlineResource/gmd:protocol/gco:CharacterString");
XPath pName = XPath.newInstance("gmd:CI_OnlineResource/gmd:name/gco:CharacterString");
XPath pDescription = XPath.newInstance("gmd:CI_OnlineResource/gmd:description/gco:CharacterString");

Element eLinkage = (Element) pLinkage.selectSingleNode(curnode);
Element eProtocol = (Element) pProtocol.selectSingleNode(curnode);
Element eName = (Element) pName.selectSingleNode(curnode);
Element eDescription = (Element) pDescription.selectSingleNode(curnode);

if (eLinkage == null) {
continue;
}
if (eProtocol == null) {
continue;
}
if (eName == null) {
continue;
}

String sLinkage = eLinkage.getValue();
String sProtocol = eProtocol.getValue();
String sName = eName.getValue();
String sDescription = eDescription != null ? eDescription.getValue() : "";

if ((sLinkage == null) || (sLinkage.equals(""))) {
continue;
}
if ((sProtocol == null) || (sProtocol.equals(""))) {
continue;
}

String sProto2 = "WMS"; // by default

if (sProtocol.contains("OGC:WMS")) {
sProto2 = "WMS";
}
else if (sProtocol.contains("OGC:WFS")) {
sProto2 = "WFS";
}
else if (sProtocol.contains("OGC:WCS")) {
sProto2 = "WMS";
}
else {
continue;
}

// If no name, we are on a service
if ((sName == null) || (sName.equals(""))) {
Element retchildserv = new Element("service");
retchildserv.setAttribute("owsurl", sLinkage);
retchildserv.setAttribute("owstype", sProto2);
retchildserv.setAttribute("text", sDescription);
retchildserv.setAttribute("mdid", id);

ret.addContent(retchildserv);
}
// else it is a Layer
else {
Element retchildlayer = new Element("layer");
retchildlayer.setAttribute("owsurl", sLinkage);
retchildlayer.setAttribute("owstype", sProto2);
retchildlayer.setAttribute("layername", sName);
retchildlayer.setAttribute("title", sDescription);
retchildlayer.setAttribute("mdid", id);
ret.addContent(retchildlayer);
}
} // for
} // iterates

return ret;
}
elems = tmp;
} catch (Exception e) {
// Bad XML input ?
continue;
}

for (Element curnode : elems) {
XPath pLinkage = XPath.newInstance("gmd:CI_OnlineResource/gmd:linkage/gmd:URL");
XPath pProtocol = XPath.newInstance("gmd:CI_OnlineResource/gmd:protocol/gco:CharacterString");
XPath pName = XPath.newInstance("gmd:CI_OnlineResource/gmd:name/gco:CharacterString");
XPath pDescription = XPath.newInstance("gmd:CI_OnlineResource/gmd:description/gco:CharacterString");

Element eLinkage = (Element) pLinkage.selectSingleNode(curnode);
Element eProtocol = (Element) pProtocol.selectSingleNode(curnode);
Element eName = (Element) pName.selectSingleNode(curnode);
Element eDescription = (Element) pDescription.selectSingleNode(curnode);

if (eLinkage == null) {
continue;
}
if (eProtocol == null) {
continue;
}
if (eName == null) {
continue;
}

String sLinkage = eLinkage.getValue();
String sProtocol = eProtocol.getValue();
String sName = eName.getValue();
String sDescription = eDescription != null ? eDescription.getValue() : "";

if ((sLinkage == null) || (sLinkage.equals(""))) {
continue;
}
if ((sProtocol == null) || (sProtocol.equals(""))) {
continue;
}

String sProto2 = "WMS"; // by default

if (sProtocol.contains("OGC:WMS")) {
sProto2 = "WMS";
}
else if (sProtocol.contains("OGC:WFS")) {
sProto2 = "WFS";
}
else if (sProtocol.contains("OGC:WCS")) {
sProto2 = "WMS";
}
else {
continue;
}

// If no name, we are on a service
if ((sName == null) || (sName.equals(""))) {
JSONObject serviceObj = new JSONObject();
serviceObj.put("owsurl", sLinkage);
serviceObj.put("owstype", sProto2);
serviceObj.put("text", sDescription);
serviceObj.put("mdid", id);
serviceObj.put("muuid", uuid);
services.add(serviceObj);
}
// else it is a Layer
else {
JSONObject layerObj = new JSONObject();
layerObj.put("owsurl", sLinkage);
layerObj.put("owstype", sProto2);
layerObj.put("layername", sName);
layerObj.put("title", sDescription);
layerObj.put("mdid", id);
layerObj.put("muuid", uuid);
layers.add(layerObj);
}
} // for
} // iterates

ret.put("layers", layers);
ret.put("services", services);

return ret;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@
removeOnlinesrc: 'resource.del.and.detach', // TODO: CHANGE
geoserverNodes: 'geoserver.publisher?_content_type=json&',
suggest: 'suggest',
facetConfig: 'search/facet/config'
facetConfig: 'search/facet/config',
selectionLayers: 'selection.layers'
});

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,17 @@
* As we cannot use nested ng-repeat on a getLinksByType()
* function, we have to load them once into the scope on rendering.
*/
module.directive('gnFixMdlinks', [
function() {
module.directive('gnFixMdlinks', [ 'gnSearchSettings',
function(gnSearchSettings) {

return {
restrict: 'A',
scope: false,
link: function(scope) {
scope.links = scope.md.getLinksByType('LINK');
scope.downloads = scope.md.getLinksByType('DOWNLOAD');
scope.layers = scope.md.getLinksByType('OGC', 'kml');
scope.maps = scope.md.getLinksByType('ows');
var obj = gnSearchSettings.linkTypes;
for(var p in obj) {
scope[p] = scope.md.getLinksByType.apply(scope.md, obj[p]);
}
}
};
}]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

module.directive('gnSelectionWidget', [
'$translate', 'hotkeys',
'gnHttp', 'gnMetadataActions',
'gnHttp', 'gnMetadataActions', 'gnSearchSettings',
function($translate, hotkeys,
gnHttp, gnMetadataActions) {
gnHttp, gnMetadataActions, gnSearchSettings) {

return {
restrict: 'A',
Expand All @@ -17,6 +17,7 @@
'selection-widget.html',
link: function(scope, element, attrs) {

scope.customActions = gnSearchSettings.customSelectActions;
var watchers = [];
scope.checkAll = true;
scope.withoutActionMenu =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,11 @@
<a href="" ng-click="mdService.deleteMd()"
data-gn-confirm-click="{{'deleteSelectedRecordConfirm' | translate:searchResults}}">
<i class="fa fa-times"></i>&nbsp;<span translate>delete</span></a></li>

<!--Custom actions-->
<li data-ng-repeat="a in customActions">
<a href="" data-ng-click="a.fn()">
<i class="fa" data-ng-class="a.icon"></i>&nbsp;<span>{{a.label | translate}}</span></a></li>

</ul>
</div>
Loading

0 comments on commit 679d21b

Please sign in to comment.