Skip to content

Commit

Permalink
Externalise metadata editor associated resources panel configuration …
Browse files Browse the repository at this point in the history
…in schemas and display fields in the dialog using the order defined in the configuration file (geonetwork#3720)

* Externalise metadata editor associated resources panel configuration in schemas and display fields in the dialog using the order defined in the configuration file

*  Externalise metadata editor associated resources panel configuration (#1)

* Externalise metadata editor associated resources panel configuration / Add possibility to define config per view.

Use the following to customize the config for a view:
```
        <directive data-gn-onlinesrc-list=""
                   data-config-id="dummy"
                   data-types="onlinesrc|parent|dataset|service|source|sibling|associated|fcats"/>
```

Also fix:
* cache retrieval was not returning same object
* add possibility to have multiple config and load them using the API

* Externalise metadata editor associated resources panel configuration / Handle depends on and more contextualized error in case of invalid JSON config.

* Externalise metadata editor associated resources panel configuration / Better loop on schema and better error report. Fix dependsOn assignement.
  • Loading branch information
josegar74 authored and fxprunayre committed Apr 10, 2019
1 parent 3971947 commit 33d0c08
Show file tree
Hide file tree
Showing 10 changed files with 451 additions and 839 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1470,6 +1470,7 @@ private void extractMetadata(MetadataSchema mds, Path xmlIdFile) throws JDOMExce

mds.setAppMinorVersionSupported(root.getChildText("appMinorVersionSupported", GEONET_SCHEMA_NS));
mds.setAppMajorVersionSupported(root.getChildText("appMajorVersionSupported", GEONET_SCHEMA_NS));
mds.setDependsOn(root.getChildText("depends", GEONET_SCHEMA_NS));
}

private Map<String, String> getSchemaIdentMultilingualProperty(Element root, String propName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ public class MetadataSchema {
private SchematronCriteriaGroupRepository criteriaGroupRepository;
private SchemaPlugin schemaPlugin;

private String dependsOn;


//---------------------------------------------------------------------------
//---
//--- Constructor
Expand Down Expand Up @@ -594,6 +597,14 @@ public void setAppMajorVersionSupported(String appMajorVersionSupported) {
this.appMajorVersionSupported = appMajorVersionSupported;
}

public String getDependsOn() {
return dependsOn;
}

public void setDependsOn(String depends) {
this.dependsOn = depends;
}

public Map<String, String> getTitles() {
return titles;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"config": {
"display": "radio",
"types": [{
"label": "addOnlinesrc",
"sources": {
"filestore": true,
"thumbnailMaker": true
},
"icon": "fa gn-icon-onlinesrc",
"process": "onlinesrc-add",
"fields": {
"url": {}
}
}]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"config": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"config": {
"display": "radio",
"types": [{
"label": "addOnlinesrc",
"sources": {
"filestore": true
},
"icon": "fa gn-icon-onlinesrc",
"process": "onlinesrc-add",
"fields": {
"protocol": {
"value": "WWW:LINK-1.0-http--link",
"isMultilingual": false,
"required": true
},
"url": {"isMultilingual": false},
"name": {},
"desc": {},
"function": {"isMultilingual": false},
"applicationProfile": {"isMultilingual": false}
}
}, {
"label": "addThumbnail",
"sources": {
"filestore": true,
"thumbnailMaker": true
},
"icon": "fa gn-icon-thumbnail",
"fileStoreFilter": "*.{jpg,JPG,png,PNG,gif,GIF}",
"process": "thumbnail-add",
"fields": {
"url": {
"param": "thumbnail_url",
"isMultilingual": false
},
"name": {"param": "thumbnail_desc"}
}
}],
"multilingualFields": ["name", "desc"]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,25 @@

package org.fao.geonet.api.standards;

import com.itextpdf.text.Meta;
import io.swagger.annotations.*;
import org.apache.commons.lang.StringUtils;
import org.fao.geonet.api.API;
import org.fao.geonet.api.ApiParams;
import org.fao.geonet.api.ApiUtils;
import org.fao.geonet.api.exception.ResourceNotFoundException;
import org.fao.geonet.api.exception.WebApplicationException;
import org.fao.geonet.api.tools.i18n.LanguageUtils;
import org.fao.geonet.kernel.Schema;
import org.fao.geonet.kernel.SchemaManager;
import org.fao.geonet.kernel.schema.MetadataSchema;
import org.fao.geonet.kernel.schema.editorconfig.BatchEditing;
import org.fao.geonet.kernel.schema.editorconfig.Editor;
import org.fao.geonet.kernel.schema.labels.Codelists;
import org.fao.geonet.utils.Xml;
import org.jdom.Element;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
Expand All @@ -48,14 +55,9 @@
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;

import javax.servlet.http.HttpServletRequest;

Expand Down Expand Up @@ -311,4 +313,64 @@ public org.fao.geonet.kernel.schema.labels.Element getElementDetails(

return (org.fao.geonet.kernel.schema.labels.Element) Xml.unmarshall(e, org.fao.geonet.kernel.schema.labels.Element.class);
}


@ApiOperation(value = "Get editor associated resources panel configuration",
nickname = "getEditorAssociatedPanelConfiguration")
@RequestMapping(value = "/{schema}/editor/associatedpanel/config/{name:[a-zA-Z]+}.json",
method = RequestMethod.GET,
produces = {
MediaType.APPLICATION_JSON_VALUE
})
@ResponseBody
public String getEditorAssociatedPanelConfiguration(
@ApiParam(value = "Schema identifier",
required = true,
example = "iso19139")
@PathVariable String schema,
@ApiParam(value = "Configuration identifier",
required = true,
defaultValue = "default",
example = "default")
@PathVariable String name
) throws Exception {
// Store processed schemas to avoid loops
Set<String> schemasProcessed = new HashSet<>();

while (StringUtils.isNotEmpty(schema) &&
!schemasProcessed.contains(schema)) {

schemasProcessed.add(schema);

MetadataSchema metadataSchema = schemaManager.getSchema(schema);

Path schemaDir = metadataSchema.getSchemaDir();

Path configFile = schemaDir.resolve("config").
resolve("associated-panel").
resolve(name + ".json");

if (Files.exists(configFile)) {
try {
String jsonConfig = new String(Files.readAllBytes(configFile));

// Parse JSON file to check is valid
new JSONObject(jsonConfig);
return jsonConfig;
} catch (Exception e) {
throw new WebApplicationException(String.format(
"Associated panel configuration '%s' for schema '%s' is invalid. Error is: %s",
name, metadataSchema.getName(), e.getMessage()));
}
} else {
// Use the file from dependent schema if available
schema = metadataSchema.getDependsOn();
}
}

throw new ResourceNotFoundException(String.format(
"Associated panel '%s' configuration not found for schema and its dependency '%s'.",
name, schemasProcessed.toString()));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,30 @@
}
}
return defer.promise;
},
/**
* Load metadata editor associated panel configuration
* for a schema.
*/
getEditorAssociationPanelConfig: function(schema, config) {
var defer = $q.defer();
var cacheKey = schema + '-associatedpanel-' + config;
var fromCache = infoCache.get(cacheKey);
if (fromCache) {
defer.resolve(fromCache);
} else {
$http.get('../api/standards/' + schema +
'/editor/associatedpanel/config/' +
(config || 'default') + '.json',
{ cache: false }).
then(function(response) {
infoCache.put(cacheKey, response.data);
defer.resolve(response.data);
}, function(response) {
defer.reject(response.data);
});
}
return defer.promise;
}
};
}]);
Expand Down
Loading

0 comments on commit 33d0c08

Please sign in to comment.