diff --git a/catalogue-plugin-framework/src/main/java/org/gcube/data/publishing/gCatFeeder/catalogues/CataloguePlugin.java b/catalogue-plugin-framework/src/main/java/org/gcube/data/publishing/gCatFeeder/catalogues/CataloguePlugin.java index 3e111cc..c0cff67 100644 --- a/catalogue-plugin-framework/src/main/java/org/gcube/data/publishing/gCatFeeder/catalogues/CataloguePlugin.java +++ b/catalogue-plugin-framework/src/main/java/org/gcube/data/publishing/gCatFeeder/catalogues/CataloguePlugin.java @@ -10,4 +10,8 @@ public interface CataloguePlugin { public CatalogueController instantiateController(CatalogueInstanceDescriptor desc) throws ControllerInstantiationFault; + + public void init() throws Exception; + + public void initInScope() throws Exception; } diff --git a/ckan-controller-plugin/target/classes/org/gcube/data/publishing/gCatFeeder/catalogues/ckan/CkanPlugin.class b/ckan-controller-plugin/target/classes/org/gcube/data/publishing/gCatFeeder/catalogues/ckan/CkanPlugin.class index c3e6317..df3ef6f 100644 Binary files a/ckan-controller-plugin/target/classes/org/gcube/data/publishing/gCatFeeder/catalogues/ckan/CkanPlugin.class and b/ckan-controller-plugin/target/classes/org/gcube/data/publishing/gCatFeeder/catalogues/ckan/CkanPlugin.class differ diff --git a/collectors-plugin-framework/src/main/java/org/gcube/data/publishing/gCatfeeder/collectors/CollectorPlugin.java b/collectors-plugin-framework/src/main/java/org/gcube/data/publishing/gCatfeeder/collectors/CollectorPlugin.java index 09d17c7..557918c 100644 --- a/collectors-plugin-framework/src/main/java/org/gcube/data/publishing/gCatfeeder/collectors/CollectorPlugin.java +++ b/collectors-plugin-framework/src/main/java/org/gcube/data/publishing/gCatfeeder/collectors/CollectorPlugin.java @@ -21,4 +21,9 @@ public interface CollectorPlugin{ public DataCollector getCollector(); public ControllerConfiguration getPublisherControllerConfiguration(String catalogueType)throws CatalogueNotSupportedException;; + + + public void init() throws Exception; + + public void initInScope() throws Exception; } diff --git a/commons/src/main/java/org/gcube/data/publishing/gCatFeeder/model/ControllerConfiguration.java b/commons/src/main/java/org/gcube/data/publishing/gCatFeeder/model/ControllerConfiguration.java index 0e3dca1..55f622b 100644 --- a/commons/src/main/java/org/gcube/data/publishing/gCatFeeder/model/ControllerConfiguration.java +++ b/commons/src/main/java/org/gcube/data/publishing/gCatFeeder/model/ControllerConfiguration.java @@ -13,4 +13,7 @@ public class ControllerConfiguration { return onClash; } + public void setOnClash(PublishingPolicy onClash) { + this.onClash = onClash; + } } diff --git a/gCat-Controller/src/main/java/org/gcube/data/publishing/gCataFeeder/catalogues/gCat/GCatController.java b/gCat-Controller/src/main/java/org/gcube/data/publishing/gCataFeeder/catalogues/gCat/GCatController.java index 42026e7..3c5bef8 100644 --- a/gCat-Controller/src/main/java/org/gcube/data/publishing/gCataFeeder/catalogues/gCat/GCatController.java +++ b/gCat-Controller/src/main/java/org/gcube/data/publishing/gCataFeeder/catalogues/gCat/GCatController.java @@ -84,6 +84,14 @@ public class GCatController implements CatalogueController{ if(isCustomToken()) resetToken(); + + + // setting default configuration + config=new ControllerConfiguration(); + config.setOnClash(PublishingPolicy.UPDATE); + + + }catch(ControllerInstantiationFault e) { throw e; } diff --git a/gCat-Controller/src/test/java/org/gcube/data/publishing/gCatFeeder/catalogues/gCat/Interactions.java b/gCat-Controller/src/test/java/org/gcube/data/publishing/gCatFeeder/catalogues/gCat/Interactions.java index b2a10e7..afbf25a 100644 --- a/gCat-Controller/src/test/java/org/gcube/data/publishing/gCatFeeder/catalogues/gCat/Interactions.java +++ b/gCat-Controller/src/test/java/org/gcube/data/publishing/gCatFeeder/catalogues/gCat/Interactions.java @@ -64,14 +64,20 @@ public class Interactions { @Test public void duplicates() { try { - publish(getController(),"full.json"); - publish(getController(),"full.json"); + publish(getController(),"full.json"); + publish(getController(),"full.json"); }catch(Exception e) { Assert.fail(e.getMessage()); } } + @Test(expected=WrongObjectFormatException.class) + public void empties() throws CatalogueInteractionException, WrongObjectFormatException, PublicationException, ControllerInstantiationFault { + publish(getController(),"empties.json"); + } + + @Test(expected=PublicationException.class) public void missingProfile() throws CatalogueInteractionException, WrongObjectFormatException, PublicationException, ControllerInstantiationFault { publish(getController(),"missingProfile.json"); diff --git a/gCat-Controller/src/test/resources/empties.json b/gCat-Controller/src/test/resources/empties.json new file mode 100644 index 0000000..6940488 --- /dev/null +++ b/gCat-Controller/src/test/resources/empties.json @@ -0,0 +1,7 @@ +{ + "profile" : null, + "item" : null, + "resources" : [ + null, + null] +} \ No newline at end of file diff --git a/gCat-Controller/src/test/resources/full.json b/gCat-Controller/src/test/resources/full.json index e69de29..8fb66dd 100644 --- a/gCat-Controller/src/test/resources/full.json +++ b/gCat-Controller/src/test/resources/full.json @@ -0,0 +1,151 @@ +{ + "profile": "\r\n \r\n Field 1<\/fieldName>\r\n false<\/mandatory>\r\n String<\/dataType>\r\n \r\n Write something here<\/note>\r\n \r\n onFieldName<\/tagging>\r\n <\/metadatafield>\r\n \r\n Field 2<\/fieldName>\r\n false<\/mandatory>\r\n Boolean<\/dataType>\r\n true<\/defaultValue>\r\n Set true or false to the checkbox<\/note>\r\n \r\n <\/metadatafield>\r\n \r\n Field 3<\/fieldName>\r\n true<\/mandatory>\r\n String<\/dataType>\r\n A<\/defaultValue>\r\n A listbox of values<\/note>\r\n \r\n A3<\/vocabularyField>\r\n B3<\/vocabularyField>\r\n C3<\/vocabularyField>\r\n D3<\/vocabularyField>\r\n E3<\/vocabularyField>\r\n F3<\/vocabularyField>\r\n <\/vocabulary>\r\n \r\n onValue<\/tagging>\r\n <\/metadatafield>\r\n \r\n Field 4<\/fieldName>\r\n true<\/mandatory>\r\n Number<\/dataType>\r\n 4<\/defaultValue>\r\n \r\n <\/metadatafield>\r\n<\/metadataformat>", + "item": { + "license_title": "Creative Commons Attribution Share-Alike 4.0", + "maintainer": null, + "searchable": "true", + "relationships_as_object": [], + "private": true, + "maintainer_email": null, + "num_tags": 2, + "metadata_created": "2019-03-19T15:03:28.482434", + "metadata_modified": "2019-03-19T15:03:30.676258", + "author": "luca_frosini", + "author_email": "luca.frosini@gcube.ckan.org", + "state": "active", + "version": null, + "creator_user_id": "287b2eec-4cd7-4e50-817f-e6dce19995c7", + "type": "dataset", + "tags": [ + { + "vocabulary_id": null, + "state": "active", + "display_name": "Other", + "id": "8ca635e2-4f72-48ed-8460-6734e9070a00", + "name": "Other" + }, + { + "vocabulary_id": null, + "state": "active", + "display_name": "REST", + "id": "3d481290-b3cd-466f-8142-51608c616e60", + "name": "REST" + } + ], + "groups": [], + "license_id": "CC-BY-SA-4.0", + "extras": [ + { + "key": "FSKX_model_parameters:Input Parameter", + "value": "standard desviation of Temperatures( sdTemp): 2.9 °c( Double)" + }, + { + "key": "FSKX_model_parameters:Output Parameter", + "value": "" + }, + { + "key": "FSKX_model_scope:Hazard", + "value": "" + }, + { + "key": "FSKX_model_scope:Population", + "value": "" + }, + { + "key": "FSKX_model_scope:Product", + "value": "" + }, + { + "key": "Item URL", + "value": "http://data.d4science.org/ctlg/AGINFRAplusDev/my_first_restful_transaction_model" + }, + { + "key": "Model Author", + "value": "" + }, + { + "key": "Model Creator", + "value": "" + }, + { + "key": "Model ID", + "value": "" + }, + { + "key": "Model Language", + "value": "Other" + }, + { + "key": "Population", + "value": "Italian" + }, + { + "key": "ReadMe", + "value": "" + }, + { + "key": "Reference Description", + "value": "" + }, + { + "key": "Related Identifier", + "value": "" + }, + { + "key": "system:type", + "value": "My Profile" + } + ] + }, + "resources": [ + { + "cache_last_updated": null, + "cache_url": null, + "mimetype_inner": null, + "hash": "", + "description": "", + "format": "", + "url": "https://data.d4science.org/shub/E_MHpyWDlKS2hPRGhKNk9ackxMY25pMDhZWEs1Z2dCTWEyNkNzbTdyMjZveDlON1RTWW9xa1FvVnprT3liSmRncA==", + "created": "2019-03-19T14:33:45.724709", + "state": "active", + "last_modified": null, + "mimetype": "application/pdf", + "url_type": null, + "position": 0, + "revision_id": "ad5fbd19-fe67-4141-ad44-cf41d90b95fb", + "size": null, + "datastore_active": false, + "resource_type": null, + "name": "RESTful Transaction Model"}, + {"cache_last_updated":null, + "cache_url":null, + "mimetype_inner":null, + "hash":"", + "description":"", + "format":"", + "url":"https://data.d4science.org/shub/E_MHpyWDlKS2hPRGhKNk9ackxMY25pMDhZWEs1Z2dCTWEyNkNzbTdyMjZveDlON1RTWW9xa1FvVnprT3liSmRncA==","created":"2019-03-19T14:33:45.724709","state":"active","last_modified":null,"mimetype":"application/pdf","url_type":null,"position":0,"revision_id":"ad5fbd19-fe67-4141-ad44-cf41d90b95fb", + "size":null, + "datastore_active":false, + "resource_type":null, + "name":"RESTful Transaction Model"}, + { + "cache_last_updated": null, + "cache_url": null, + "mimetype_inner": null, + "hash": "", + "description": "", + "format": "", + "url": "https://data.d4science.org/shub/E_MHpyWDlKS2hPRGhKNk9ackxMY25pMDhZWEs1Z2dCTWEyNkNzbTdyMjZveDlON1RTWW9xa1FvVnprT3liSmRncA==", + "created": "2019-03-19T14:33:45.724709", + "state": "active", + "last_modified": null, + "mimetype": "application/pdf", + "url_type": null, + "position": 0, + "revision_id": "ad5fbd19-fe67-4141-ad44-cf41d90b95fb", + "size": null, + "datastore_active": false, + "resource_type": null, + "name": "RESTful Transaction Model2" + },null] +} \ No newline at end of file diff --git a/gCat-Controller/src/test/resources/missingProfile.json b/gCat-Controller/src/test/resources/missingProfile.json index e69de29..0f3824d 100644 --- a/gCat-Controller/src/test/resources/missingProfile.json +++ b/gCat-Controller/src/test/resources/missingProfile.json @@ -0,0 +1,123 @@ +{ + "profile": null, + "item": { + "license_title": "Creative Commons Attribution Share-Alike 4.0", + "maintainer": null, + "searchable": "true", + "relationships_as_object": [], + "private": true, + "maintainer_email": null, + "num_tags": 2, + "metadata_created": "2019-03-19T15:03:28.482434", + "metadata_modified": "2019-03-19T15:03:30.676258", + "author": "luca_frosini", + "author_email": "luca.frosini@gcube.ckan.org", + "state": "active", + "version": null, + "creator_user_id": "287b2eec-4cd7-4e50-817f-e6dce19995c7", + "type": "dataset", + "tags": [ + { + "vocabulary_id": null, + "state": "active", + "display_name": "Other", + "id": "8ca635e2-4f72-48ed-8460-6734e9070a00", + "name": "Other" + }, + { + "vocabulary_id": null, + "state": "active", + "display_name": "REST", + "id": "3d481290-b3cd-466f-8142-51608c616e60", + "name": "REST" + } + ], + "groups": [], + "license_id": "CC-BY-SA-4.0", + "extras": [ + { + "key": "FSKX_model_parameters:Input Parameter", + "value": "standard desviation of Temperatures( sdTemp): 2.9 °c( Double)" + }, + { + "key": "FSKX_model_parameters:Output Parameter", + "value": "" + }, + { + "key": "FSKX_model_scope:Hazard", + "value": "" + }, + { + "key": "FSKX_model_scope:Population", + "value": "" + }, + { + "key": "FSKX_model_scope:Product", + "value": "" + }, + { + "key": "Item URL", + "value": "http://data.d4science.org/ctlg/AGINFRAplusDev/my_first_restful_transaction_model" + }, + { + "key": "Model Author", + "value": "" + }, + { + "key": "Model Creator", + "value": "" + }, + { + "key": "Model ID", + "value": "" + }, + { + "key": "Model Language", + "value": "Other" + }, + { + "key": "Population", + "value": "Italian" + }, + { + "key": "ReadMe", + "value": "" + }, + { + "key": "Reference Description", + "value": "" + }, + { + "key": "Related Identifier", + "value": "" + }, + { + "key": "system:type", + "value": "SomeFakeProfile" + } + ] + }, + "resources": [ + { + "cache_last_updated": null, + "cache_url": null, + "mimetype_inner": null, + "hash": "", + "description": "", + "format": "", + "url": "https://data.d4science.org/shub/E_MHpyWDlKS2hPRGhKNk9ackxMY25pMDhZWEs1Z2dCTWEyNkNzbTdyMjZveDlON1RTWW9xa1FvVnprT3liSmRncA==", + "created": "2019-03-19T14:33:45.724709", + "state": "active", + "last_modified": null, + "mimetype": "application/pdf", + "url_type": null, + "position": 0, + "revision_id": "ad5fbd19-fe67-4141-ad44-cf41d90b95fb", + "size": null, + "datastore_active": false, + "resource_type": null, + "name": "RESTful Transaction Model" + }, + null + ] +} \ No newline at end of file diff --git a/gCat-Controller/src/test/resources/noItem.json b/gCat-Controller/src/test/resources/noItem.json index e69de29..3057d78 100644 --- a/gCat-Controller/src/test/resources/noItem.json +++ b/gCat-Controller/src/test/resources/noItem.json @@ -0,0 +1,20 @@ +{ + "cache_last_updated": null, + "cache_url": null, + "mimetype_inner": null, + "hash": "", + "description": "", + "format": "", + "url": "https://data.d4science.org/shub/E_MHpyWDlKS2hPRGhKNk9ackxMY25pMDhZWEs1Z2dCTWEyNkNzbTdyMjZveDlON1RTWW9xa1FvVnprT3liSmRncA==", + "created": "2019-03-19T14:33:45.724709", + "state": "active", + "last_modified": null, + "mimetype": "application/pdf", + "url_type": null, + "position": 0, + "revision_id": "ad5fbd19-fe67-4141-ad44-cf41d90b95fb", + "size": null, + "datastore_active": false, + "resource_type": null, + "name": "RESTful Transaction Model" + } \ No newline at end of file diff --git a/gCat-Controller/target/classes/org/gcube/data/publishing/gCataFeeder/catalogues/gCat/GCatController.class b/gCat-Controller/target/classes/org/gcube/data/publishing/gCataFeeder/catalogues/gCat/GCatController.class index 132f1eb..1825a95 100644 Binary files a/gCat-Controller/target/classes/org/gcube/data/publishing/gCataFeeder/catalogues/gCat/GCatController.class and b/gCat-Controller/target/classes/org/gcube/data/publishing/gCataFeeder/catalogues/gCat/GCatController.class differ diff --git a/gCat-Controller/target/classes/org/gcube/data/publishing/gCataFeeder/catalogues/gCat/GCatPlugin.class b/gCat-Controller/target/classes/org/gcube/data/publishing/gCataFeeder/catalogues/gCat/GCatPlugin.class index 263040c..34c79c9 100644 Binary files a/gCat-Controller/target/classes/org/gcube/data/publishing/gCataFeeder/catalogues/gCat/GCatPlugin.class and b/gCat-Controller/target/classes/org/gcube/data/publishing/gCataFeeder/catalogues/gCat/GCatPlugin.class differ diff --git a/gCat-Controller/target/test-classes/empties.json b/gCat-Controller/target/test-classes/empties.json new file mode 100644 index 0000000..6940488 --- /dev/null +++ b/gCat-Controller/target/test-classes/empties.json @@ -0,0 +1,7 @@ +{ + "profile" : null, + "item" : null, + "resources" : [ + null, + null] +} \ No newline at end of file diff --git a/gCat-Controller/target/test-classes/full.json b/gCat-Controller/target/test-classes/full.json index e69de29..8fb66dd 100644 --- a/gCat-Controller/target/test-classes/full.json +++ b/gCat-Controller/target/test-classes/full.json @@ -0,0 +1,151 @@ +{ + "profile": "\r\n \r\n Field 1<\/fieldName>\r\n false<\/mandatory>\r\n String<\/dataType>\r\n \r\n Write something here<\/note>\r\n \r\n onFieldName<\/tagging>\r\n <\/metadatafield>\r\n \r\n Field 2<\/fieldName>\r\n false<\/mandatory>\r\n Boolean<\/dataType>\r\n true<\/defaultValue>\r\n Set true or false to the checkbox<\/note>\r\n \r\n <\/metadatafield>\r\n \r\n Field 3<\/fieldName>\r\n true<\/mandatory>\r\n String<\/dataType>\r\n A<\/defaultValue>\r\n A listbox of values<\/note>\r\n \r\n A3<\/vocabularyField>\r\n B3<\/vocabularyField>\r\n C3<\/vocabularyField>\r\n D3<\/vocabularyField>\r\n E3<\/vocabularyField>\r\n F3<\/vocabularyField>\r\n <\/vocabulary>\r\n \r\n onValue<\/tagging>\r\n <\/metadatafield>\r\n \r\n Field 4<\/fieldName>\r\n true<\/mandatory>\r\n Number<\/dataType>\r\n 4<\/defaultValue>\r\n \r\n <\/metadatafield>\r\n<\/metadataformat>", + "item": { + "license_title": "Creative Commons Attribution Share-Alike 4.0", + "maintainer": null, + "searchable": "true", + "relationships_as_object": [], + "private": true, + "maintainer_email": null, + "num_tags": 2, + "metadata_created": "2019-03-19T15:03:28.482434", + "metadata_modified": "2019-03-19T15:03:30.676258", + "author": "luca_frosini", + "author_email": "luca.frosini@gcube.ckan.org", + "state": "active", + "version": null, + "creator_user_id": "287b2eec-4cd7-4e50-817f-e6dce19995c7", + "type": "dataset", + "tags": [ + { + "vocabulary_id": null, + "state": "active", + "display_name": "Other", + "id": "8ca635e2-4f72-48ed-8460-6734e9070a00", + "name": "Other" + }, + { + "vocabulary_id": null, + "state": "active", + "display_name": "REST", + "id": "3d481290-b3cd-466f-8142-51608c616e60", + "name": "REST" + } + ], + "groups": [], + "license_id": "CC-BY-SA-4.0", + "extras": [ + { + "key": "FSKX_model_parameters:Input Parameter", + "value": "standard desviation of Temperatures( sdTemp): 2.9 °c( Double)" + }, + { + "key": "FSKX_model_parameters:Output Parameter", + "value": "" + }, + { + "key": "FSKX_model_scope:Hazard", + "value": "" + }, + { + "key": "FSKX_model_scope:Population", + "value": "" + }, + { + "key": "FSKX_model_scope:Product", + "value": "" + }, + { + "key": "Item URL", + "value": "http://data.d4science.org/ctlg/AGINFRAplusDev/my_first_restful_transaction_model" + }, + { + "key": "Model Author", + "value": "" + }, + { + "key": "Model Creator", + "value": "" + }, + { + "key": "Model ID", + "value": "" + }, + { + "key": "Model Language", + "value": "Other" + }, + { + "key": "Population", + "value": "Italian" + }, + { + "key": "ReadMe", + "value": "" + }, + { + "key": "Reference Description", + "value": "" + }, + { + "key": "Related Identifier", + "value": "" + }, + { + "key": "system:type", + "value": "My Profile" + } + ] + }, + "resources": [ + { + "cache_last_updated": null, + "cache_url": null, + "mimetype_inner": null, + "hash": "", + "description": "", + "format": "", + "url": "https://data.d4science.org/shub/E_MHpyWDlKS2hPRGhKNk9ackxMY25pMDhZWEs1Z2dCTWEyNkNzbTdyMjZveDlON1RTWW9xa1FvVnprT3liSmRncA==", + "created": "2019-03-19T14:33:45.724709", + "state": "active", + "last_modified": null, + "mimetype": "application/pdf", + "url_type": null, + "position": 0, + "revision_id": "ad5fbd19-fe67-4141-ad44-cf41d90b95fb", + "size": null, + "datastore_active": false, + "resource_type": null, + "name": "RESTful Transaction Model"}, + {"cache_last_updated":null, + "cache_url":null, + "mimetype_inner":null, + "hash":"", + "description":"", + "format":"", + "url":"https://data.d4science.org/shub/E_MHpyWDlKS2hPRGhKNk9ackxMY25pMDhZWEs1Z2dCTWEyNkNzbTdyMjZveDlON1RTWW9xa1FvVnprT3liSmRncA==","created":"2019-03-19T14:33:45.724709","state":"active","last_modified":null,"mimetype":"application/pdf","url_type":null,"position":0,"revision_id":"ad5fbd19-fe67-4141-ad44-cf41d90b95fb", + "size":null, + "datastore_active":false, + "resource_type":null, + "name":"RESTful Transaction Model"}, + { + "cache_last_updated": null, + "cache_url": null, + "mimetype_inner": null, + "hash": "", + "description": "", + "format": "", + "url": "https://data.d4science.org/shub/E_MHpyWDlKS2hPRGhKNk9ackxMY25pMDhZWEs1Z2dCTWEyNkNzbTdyMjZveDlON1RTWW9xa1FvVnprT3liSmRncA==", + "created": "2019-03-19T14:33:45.724709", + "state": "active", + "last_modified": null, + "mimetype": "application/pdf", + "url_type": null, + "position": 0, + "revision_id": "ad5fbd19-fe67-4141-ad44-cf41d90b95fb", + "size": null, + "datastore_active": false, + "resource_type": null, + "name": "RESTful Transaction Model2" + },null] +} \ No newline at end of file diff --git a/gCat-Controller/target/test-classes/missingProfile.json b/gCat-Controller/target/test-classes/missingProfile.json index e69de29..0f3824d 100644 --- a/gCat-Controller/target/test-classes/missingProfile.json +++ b/gCat-Controller/target/test-classes/missingProfile.json @@ -0,0 +1,123 @@ +{ + "profile": null, + "item": { + "license_title": "Creative Commons Attribution Share-Alike 4.0", + "maintainer": null, + "searchable": "true", + "relationships_as_object": [], + "private": true, + "maintainer_email": null, + "num_tags": 2, + "metadata_created": "2019-03-19T15:03:28.482434", + "metadata_modified": "2019-03-19T15:03:30.676258", + "author": "luca_frosini", + "author_email": "luca.frosini@gcube.ckan.org", + "state": "active", + "version": null, + "creator_user_id": "287b2eec-4cd7-4e50-817f-e6dce19995c7", + "type": "dataset", + "tags": [ + { + "vocabulary_id": null, + "state": "active", + "display_name": "Other", + "id": "8ca635e2-4f72-48ed-8460-6734e9070a00", + "name": "Other" + }, + { + "vocabulary_id": null, + "state": "active", + "display_name": "REST", + "id": "3d481290-b3cd-466f-8142-51608c616e60", + "name": "REST" + } + ], + "groups": [], + "license_id": "CC-BY-SA-4.0", + "extras": [ + { + "key": "FSKX_model_parameters:Input Parameter", + "value": "standard desviation of Temperatures( sdTemp): 2.9 °c( Double)" + }, + { + "key": "FSKX_model_parameters:Output Parameter", + "value": "" + }, + { + "key": "FSKX_model_scope:Hazard", + "value": "" + }, + { + "key": "FSKX_model_scope:Population", + "value": "" + }, + { + "key": "FSKX_model_scope:Product", + "value": "" + }, + { + "key": "Item URL", + "value": "http://data.d4science.org/ctlg/AGINFRAplusDev/my_first_restful_transaction_model" + }, + { + "key": "Model Author", + "value": "" + }, + { + "key": "Model Creator", + "value": "" + }, + { + "key": "Model ID", + "value": "" + }, + { + "key": "Model Language", + "value": "Other" + }, + { + "key": "Population", + "value": "Italian" + }, + { + "key": "ReadMe", + "value": "" + }, + { + "key": "Reference Description", + "value": "" + }, + { + "key": "Related Identifier", + "value": "" + }, + { + "key": "system:type", + "value": "SomeFakeProfile" + } + ] + }, + "resources": [ + { + "cache_last_updated": null, + "cache_url": null, + "mimetype_inner": null, + "hash": "", + "description": "", + "format": "", + "url": "https://data.d4science.org/shub/E_MHpyWDlKS2hPRGhKNk9ackxMY25pMDhZWEs1Z2dCTWEyNkNzbTdyMjZveDlON1RTWW9xa1FvVnprT3liSmRncA==", + "created": "2019-03-19T14:33:45.724709", + "state": "active", + "last_modified": null, + "mimetype": "application/pdf", + "url_type": null, + "position": 0, + "revision_id": "ad5fbd19-fe67-4141-ad44-cf41d90b95fb", + "size": null, + "datastore_active": false, + "resource_type": null, + "name": "RESTful Transaction Model" + }, + null + ] +} \ No newline at end of file diff --git a/gCat-Controller/target/test-classes/noItem.json b/gCat-Controller/target/test-classes/noItem.json index e69de29..3057d78 100644 --- a/gCat-Controller/target/test-classes/noItem.json +++ b/gCat-Controller/target/test-classes/noItem.json @@ -0,0 +1,20 @@ +{ + "cache_last_updated": null, + "cache_url": null, + "mimetype_inner": null, + "hash": "", + "description": "", + "format": "", + "url": "https://data.d4science.org/shub/E_MHpyWDlKS2hPRGhKNk9ackxMY25pMDhZWEs1Z2dCTWEyNkNzbTdyMjZveDlON1RTWW9xa1FvVnprT3liSmRncA==", + "created": "2019-03-19T14:33:45.724709", + "state": "active", + "last_modified": null, + "mimetype": "application/pdf", + "url_type": null, + "position": 0, + "revision_id": "ad5fbd19-fe67-4141-ad44-cf41d90b95fb", + "size": null, + "datastore_active": false, + "resource_type": null, + "name": "RESTful Transaction Model" + } \ No newline at end of file diff --git a/gCat-Controller/target/test-classes/org/gcube/data/publishing/gCatFeeder/catalogues/gCat/Interactions.class b/gCat-Controller/target/test-classes/org/gcube/data/publishing/gCatFeeder/catalogues/gCat/Interactions.class index 5027aec..912f015 100644 Binary files a/gCat-Controller/target/test-classes/org/gcube/data/publishing/gCatFeeder/catalogues/gCat/Interactions.class and b/gCat-Controller/target/test-classes/org/gcube/data/publishing/gCatFeeder/catalogues/gCat/Interactions.class differ diff --git a/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/ServiceConstants.java b/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/ServiceConstants.java index 01985be..3942108 100644 --- a/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/ServiceConstants.java +++ b/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/ServiceConstants.java @@ -12,4 +12,11 @@ public class ServiceConstants { public static final String EXECUTION_ID_PARAMETER="executionId"; } + public static interface Capabilities{ + public static final String PATH="capabilities"; + + public static final String COLLECTORS_PATH="collectors"; + + public static final String CATALOGUES_PATH="catalogues"; + } } diff --git a/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/engine/CatalogueControllersManager.java b/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/engine/CatalogueControllersManager.java index fe6f68a..bb89ad8 100644 --- a/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/engine/CatalogueControllersManager.java +++ b/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/engine/CatalogueControllersManager.java @@ -14,4 +14,6 @@ public interface CatalogueControllersManager { public void init() throws InternalError; + + public void initInScope() throws InternalError; } diff --git a/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/engine/CollectorsManager.java b/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/engine/CollectorsManager.java index 1e7c6a9..bd52811 100644 --- a/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/engine/CollectorsManager.java +++ b/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/engine/CollectorsManager.java @@ -12,4 +12,7 @@ public interface CollectorsManager { public CollectorPlugin getPluginById(String collectorId) throws CollectorNotFound; public void init() throws InternalError; + + + public void initInScope() throws InternalError; } diff --git a/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/engine/impl/CatalogueControllersManagerImpl.java b/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/engine/impl/CatalogueControllersManagerImpl.java new file mode 100644 index 0000000..5d54bf8 --- /dev/null +++ b/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/engine/impl/CatalogueControllersManagerImpl.java @@ -0,0 +1,80 @@ +package org.gcube.data.publishing.gCatFeeder.service.engine.impl; + +import java.util.Map.Entry; +import java.util.ServiceLoader; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; + +import javax.inject.Singleton; + +import org.gcube.data.publishing.gCatFeeder.catalogues.CataloguePlugin; +import org.gcube.data.publishing.gCatFeeder.service.engine.CatalogueControllersManager; +import org.gcube.data.publishing.gCatFeeder.service.model.fault.CataloguePluginNotFound; +import org.gcube.data.publishing.gCatFeeder.service.model.fault.InternalError; +import org.gcube.data.publishing.gCatFeeder.utils.ContextUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Singleton +public class CatalogueControllersManagerImpl implements CatalogueControllersManager { + + private static final Logger log= LoggerFactory.getLogger(CatalogueControllersManagerImpl.class); + + + private ServiceLoader cataloguePluginsLoader = null; + + private ConcurrentHashMap availablePlugins=null; + + + public CatalogueControllersManagerImpl() { + //load plugins + log.debug("Loading catalogue plugins..."); + cataloguePluginsLoader=ServiceLoader.load(CataloguePlugin.class); + for(CataloguePlugin plugin:cataloguePluginsLoader) { + log.debug("Loading {} ",plugin.getClass()); + log.debug("Descriptor {} ",plugin.getDescriptor()); + availablePlugins.put(plugin.getDescriptor().getId(), plugin); + } + log.trace("Loaded {} catalogue plugins ",availablePlugins.size()); + } + + + + @Override + public Set getAvailableControllers() { + return availablePlugins.keySet(); + } + + @Override + public CataloguePlugin getPluginById(String pluginId) throws CataloguePluginNotFound { + if(availablePlugins.containsKey(pluginId)) return availablePlugins.get(pluginId); + else throw new CataloguePluginNotFound("Catalogue plugin "+pluginId+" not available."); + } + + @Override + public void init() throws InternalError { + log.trace("Static initialization..."); + for(Entry entry:availablePlugins.entrySet()) { + log.debug("Static initialization for : {} ",entry.getKey()); + try { + entry.getValue().init(); + }catch(Throwable t) { + log.error("Unexpected exception while initializing {} ",entry.getKey(),t); + } + } + } + + @Override + public void initInScope() throws InternalError { + log.trace("Initialization under scope {} ",ContextUtils.getCurrentScope()); + for(Entry entry:availablePlugins.entrySet()) { + log.debug("Scope initialization for : {} ",entry.getKey()); + try { + entry.getValue().initInScope(); + }catch(Throwable t) { + log.error("Unexpected exception while initializing {} ",entry.getKey(),t); + } + } + } + +} diff --git a/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/engine/impl/CollectorsManagerImpl.java b/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/engine/impl/CollectorsManagerImpl.java new file mode 100644 index 0000000..debdbdf --- /dev/null +++ b/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/engine/impl/CollectorsManagerImpl.java @@ -0,0 +1,83 @@ +package org.gcube.data.publishing.gCatFeeder.service.engine.impl; + +import java.util.ServiceLoader; +import java.util.Set; +import java.util.Map.Entry; +import java.util.concurrent.ConcurrentHashMap; + +import javax.inject.Singleton; + +import org.gcube.data.publishing.gCatFeeder.catalogues.CataloguePlugin; +import org.gcube.data.publishing.gCatFeeder.service.engine.CollectorsManager; +import org.gcube.data.publishing.gCatFeeder.service.model.fault.CataloguePluginNotFound; +import org.gcube.data.publishing.gCatFeeder.service.model.fault.CollectorNotFound; +import org.gcube.data.publishing.gCatFeeder.service.model.fault.InternalError; +import org.gcube.data.publishing.gCatFeeder.utils.ContextUtils; +import org.gcube.data.publishing.gCatfeeder.collectors.CollectorPlugin; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Singleton +public class CollectorsManagerImpl implements CollectorsManager { + + + private static final Logger log= LoggerFactory.getLogger(CollectorsManagerImpl.class); + + + private ServiceLoader collectorPluginsLoader = null; + + private ConcurrentHashMap availablePlugins=null; + + + public CollectorsManagerImpl() { + //load plugins + log.debug("Loading collector plugins..."); + collectorPluginsLoader=ServiceLoader.load(CollectorPlugin.class); + for(CollectorPlugin plugin:collectorPluginsLoader) { + log.debug("Loading {} ",plugin.getClass()); + log.debug("Descriptor {} ",plugin.getDescriptor()); + availablePlugins.put(plugin.getDescriptor().getName(), plugin); + } + log.trace("Loaded {} collector plugins ",availablePlugins.size()); + } + + + @Override + public Set getAvailableCollectors() { + return availablePlugins.keySet(); + } + + @Override + public CollectorPlugin getPluginById(String collectorId) throws CollectorNotFound { + if(availablePlugins.containsKey(collectorId)) return availablePlugins.get(collectorId); + else throw new CollectorNotFound("Collector plugin "+collectorId+" not available."); + } + + @Override + public void init() throws InternalError { + log.trace("Static initialization..."); + for(Entry entry:availablePlugins.entrySet()) { + log.debug("Static initialization for : {} ",entry.getKey()); + try { + entry.getValue().init(); + }catch(Throwable t) { + log.error("Unexpected exception while initializing {} ",entry.getKey(),t); + } + } + } + + + @Override + public void initInScope() throws InternalError { + log.trace("Initialization under scope {} ",ContextUtils.getCurrentScope()); + for(Entry entry:availablePlugins.entrySet()) { + log.debug("Scope initialization for : {} ",entry.getKey()); + try { + entry.getValue().initInScope(); + }catch(Throwable t) { + log.error("Unexpected exception while initializing {} ",entry.getKey(),t); + } + } + } + +} diff --git a/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/engine/impl/ExecutionTask.java b/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/engine/impl/ExecutionTask.java index 9abdc21..f08073b 100644 --- a/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/engine/impl/ExecutionTask.java +++ b/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/engine/impl/ExecutionTask.java @@ -1,6 +1,5 @@ package org.gcube.data.publishing.gCatFeeder.service.engine.impl; -import java.io.File; import java.io.Serializable; import java.time.Instant; import java.util.Set; @@ -11,7 +10,9 @@ import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.data.publishing.gCatFeeder.catalogues.CatalogueController; import org.gcube.data.publishing.gCatFeeder.catalogues.CataloguePlugin; import org.gcube.data.publishing.gCatFeeder.catalogues.model.PublishReport; +import org.gcube.data.publishing.gCatFeeder.catalogues.model.faults.CatalogueInteractionException; import org.gcube.data.publishing.gCatFeeder.catalogues.model.faults.ControllerInstantiationFault; +import org.gcube.data.publishing.gCatFeeder.catalogues.model.faults.PublicationException; import org.gcube.data.publishing.gCatFeeder.catalogues.model.faults.WrongObjectFormatException; import org.gcube.data.publishing.gCatFeeder.model.CatalogueFormatData; import org.gcube.data.publishing.gCatFeeder.model.CatalogueInstanceDescriptor; @@ -184,6 +185,10 @@ public class ExecutionTask implements Runnable { PublishReport itemReport=controller.publishItem(item); }catch(WrongObjectFormatException e) { catalogueReport.getPublishedRecords().add(new PublishReport(false,"Wrong format : "+e.getMessage())); + } catch (CatalogueInteractionException e) { + catalogueReport.getPublishedRecords().add(new PublishReport(false,"Error while communicating with catalogue : "+e.getMessage())); + } catch (PublicationException e) { + catalogueReport.getPublishedRecords().add(new PublishReport(false,"Publication error : "+e.getMessage())); } } diff --git a/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/model/CapabilitiesBean.java b/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/model/CapabilitiesBean.java new file mode 100644 index 0000000..e4e3061 --- /dev/null +++ b/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/model/CapabilitiesBean.java @@ -0,0 +1,5 @@ +package org.gcube.data.publishing.gCatFeeder.service.model; + +public class CapabilitiesBean { + +} diff --git a/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/rest/Capabilities.java b/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/rest/Capabilities.java new file mode 100644 index 0000000..8f92931 --- /dev/null +++ b/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/rest/Capabilities.java @@ -0,0 +1,74 @@ +package org.gcube.data.publishing.gCatFeeder.service.rest; + +import java.util.ArrayList; +import java.util.Collection; + +import javax.inject.Inject; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.GenericEntity; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.gcube.data.publishing.gCatFeeder.catalogues.model.CataloguePluginDescriptor; +import org.gcube.data.publishing.gCatFeeder.service.GCatFeederManager; +import org.gcube.data.publishing.gCatFeeder.service.ServiceConstants; +import org.gcube.data.publishing.gCatFeeder.service.engine.CatalogueControllersManager; +import org.gcube.data.publishing.gCatFeeder.service.engine.CollectorsManager; +import org.gcube.data.publishing.gCatfeeder.collectors.model.PluginDescriptor; +import org.gcube.smartgears.annotations.ManagedBy; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@ManagedBy(GCatFeederManager.class) +@Path(ServiceConstants.Executions.PATH) +public class Capabilities { + + private static final Logger log= LoggerFactory.getLogger(Capabilities.class); + + + @Inject + private CatalogueControllersManager catalogues; + + @Inject + private CollectorsManager collectors; + + + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path(ServiceConstants.Capabilities.COLLECTORS_PATH) + public Response getCollectorCapabilities() { + try { + ArrayList toReturn=new ArrayList<>(); + for(String s:collectors.getAvailableCollectors()) { + toReturn.add(collectors.getPluginById(s).getDescriptor()); + } + GenericEntity> entity=new GenericEntity>(toReturn) {}; + return Response.ok(entity).build(); + }catch(Throwable t) { + log.warn("Unexpected Exception ",t); + throw new WebApplicationException("Unexpected Exception.", t,Response.Status.INTERNAL_SERVER_ERROR); + } + } + + + + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path(ServiceConstants.Capabilities.CATALOGUES_PATH) + public Response getCataloguesCapabilities() { + try { + ArrayList toReturn=new ArrayList<>(); + for(String s:catalogues.getAvailableControllers()) { + toReturn.add(catalogues.getPluginById(s).getDescriptor()); + } + GenericEntity> entity=new GenericEntity>(toReturn) {}; + return Response.ok(entity).build(); + }catch(Throwable t) { + log.warn("Unexpected Exception ",t); + throw new WebApplicationException("Unexpected Exception.", t,Response.Status.INTERNAL_SERVER_ERROR); + } + } +} diff --git a/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/rest/Executions.java b/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/rest/Executions.java index 6a042f5..691f207 100644 --- a/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/rest/Executions.java +++ b/gCat-Feeder/src/main/java/org/gcube/data/publishing/gCatFeeder/service/rest/Executions.java @@ -13,6 +13,7 @@ import javax.ws.rs.core.GenericEntity; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import org.gcube.data.publishing.gCatFeeder.service.GCatFeederManager; import org.gcube.data.publishing.gCatFeeder.service.ServiceConstants; import org.gcube.data.publishing.gCatFeeder.service.engine.FeederEngine; import org.gcube.data.publishing.gCatFeeder.service.model.ExecutionDescriptor; @@ -21,9 +22,11 @@ import org.gcube.data.publishing.gCatFeeder.service.model.ExecutionRequest; import org.gcube.data.publishing.gCatFeeder.service.model.fault.ElementNotFound; import org.gcube.data.publishing.gCatFeeder.service.model.fault.InvalidRequest; import org.gcube.data.publishing.gCatFeeder.service.model.fault.PersistenceError; +import org.gcube.smartgears.annotations.ManagedBy; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@ManagedBy(GCatFeederManager.class) @Path(ServiceConstants.Executions.PATH) public class Executions {