Commit cdc843a1 authored by Matija Obreza's avatar Matija Obreza
Browse files

API Documentation updated

- Upgrade to application-blocks-security:1.3-SNAPSHOT
- Removed obsolete tests
parent 52d7317e
......@@ -3,37 +3,41 @@
== Managing Passport Data
Passport data is based on FAO Multi-Crop Passport Descriptors <<mcpd2>> format.
Passport data is based on FAO Multi-Crop Passport Descriptors <<mcpd2>> format.
Accession records are *upserted*, meaning that when the matching accession record
Accession records are *upserted*, meaning that when the matching accession record
. exists, it will be updated
. does not exist, a new record will be created
Accession data in the database will be updated with whatever data is provided in the
Accession data in the database will be updated with whatever data is provided in the
request JSON.
=== Accession identity
Prior to full adoption of Permanent Unique Identifiers for Germplasm, accessions could be
identified by the holding institute code (INSTCODE) and the accession number (ACCENUMB).
Genebanks maintaining two or more collections of crops would sometimes use the same
accession number, unique within one collection.
Genebanks maintaining two or more collections of crops would sometimes use the same
accession number, unique within one collection.
Genesys uses the *instCode*, *acceNumb* and *genus* triplet to uniquely identify an
accession in an institute:
Genesys uses the *instCode*, *acceNumb* and *genus* triplet to uniquely identify an
accession in an institute. For accessions with a <<doi, DOI>> assigned in <<glis, GLIS>> it will
use the DOI to uniquely identify the record:
[source,json,linenums]
----
{
"instCode": "NGA039", <1>
"acceNumb": "TMp-123", <2>
"genus": "Musa" <3>
"doi": "10.1054/12A1~", <2>
"acceNumb": "TMp-123", <3>
"genus": "Musa", <4>
...
}
----
<1> Holding institute code (INSTCODE)
<2> Accession number (ACCENUMB)
<3> Genus (GENUS)
<2> DOI of the accession as registered in GLIS
<3> Accession number (ACCENUMB)
<4> Genus (GENUS)
=== JSON data model
......@@ -54,6 +58,7 @@ All other fields are optional.
----
{
"instCode": "XYZ111",
"doi": "10.1231/14S41Q",
"acceNumb": "M12345",
"cropName": "banana",
"genus": "Musa",
......@@ -177,8 +182,8 @@ as `null`. Not providing a field means the field in the database should not be m
=== Insert or update accessions
REST endpoint URL `/api/v0/acn/{instCode}/upsert` allows for inserting new accessions
or updating existing records in Genesys. It accepts a JSON array of Accession JSON objects.
REST endpoint URL `/api/v0/acn/{instCode}/upsert` allows for inserting new accessions
or updating existing records in Genesys. It accepts a JSON array of Accession JSON objects.
The array provides for sending batches of 50 or 100 accessions in one call, reducing
the HTTP overhead and improving performance.
......@@ -223,6 +228,7 @@ POST /api/v0/acn/SYR002/delete
[bibliography]
- [[[mcpd2]]] Alercia, A; Diulgheroff, S; Mackay, M.
- [[[mcpd2]]] Alercia, A; Diulgheroff, S; Mackay, M.
http://www.bioversityinternational.org/e-library/publications/detail/faobioversity-multi-crop-passport-descriptors-v2-mcpd-v2/[FAO/Bioversity Multi-Crop Passport Descriptors V.2]. 2012.
- [[[glis]]] ITPGRFA Secretariat
http://www.fao.org/plant-treaty/areas-of-work/global-information-system/en/[Global Information System].
......@@ -6,12 +6,12 @@ Access to selected resources in Genesys is protected and user permissions are ch
any API action is executed. Each organization contributing data to Genesys will have
one or more registered user accounts on Genesys.
To modify any data in Genesys, you will need appropriate permissions.
Permission to access and manage data for the organization is granted by
helpdesk@genesys-pgr.org upon request. Please contact helpdesk@genesys-pgr.org with the list
To modify any data in Genesys, you will need appropriate permissions.
Permission to access and manage data for the organization is granted by
helpdesk@genesys-pgr.org upon request. Please contact helpdesk@genesys-pgr.org with the list
of WIEWS codes of institutes you wish to manage.
To access resources with the APIs described in this manual, you will first need to
To access resources with the APIs described in this manual, you will first need to
create a user account. The simplest is to https://sandbox.genesys-pgr.org/google/login[use your Google+ account]
or alternatively https://sandbox.genesys-pgr.org/registration[creating an account manually].
......@@ -20,17 +20,17 @@ image::user-account-create.png[role="text-center"]
Access to the APIs is managed by https://en.wikipedia.org/wiki/OAuth#OAuth_2.0[OAuth 2.0] protocol and implemented
using http://docs.spring.io/spring-security/oauth/[spring-security OAuth]
modules. All API access is over HTTPS, and accessed from the https://www.genesys-pgr.org domain or
through https://sandbox.genesys-pgr.org for testing purposes.
modules. All API access is over HTTPS, and accessed from the https://www.genesys-pgr.org domain or
through https://sandbox.genesys-pgr.org for testing purposes.
To obtain OAuth access and refresh tokens, you will first need a valid Client ID and Client Secret.
These are generated by helpdesk@genesys-pgr.org for each individual consumer application.
These are generated by helpdesk@genesys-pgr.org for each individual consumer application.
The ID and Secret listed below are valid for the Sandbox environment and allows of out-of-band authentication
when using `curl` in the examples in this manual.
[cols="1,2"]
.Client ID and Secret for OOB
[cols="1,2"]
.Client ID and Secret for OOB
|===
|Client ID
|`dLCiR.MzwkNha18ImEcw0ADli0@sandbox.genesys-pgr.org`
......@@ -42,17 +42,17 @@ when using `curl` in the examples in this manual.
=== Obtaining the access token
Most OAuth libraries, including https://bitbucket.org/genesys2/genesys-client-api[genesys-client-api]
Java library, will automatically obtain the access token following the OAuth protocol. This
Java library, will automatically obtain the access token following the OAuth protocol. This
section describes how to manually obtain the tokens.
Log-in to Genesys with your account or Google+
Obtain a verifier code by granting access to the "Genesys API reference" client. This is
Obtain a verifier code by granting access to the "Genesys API reference" client. This is
initiated by opening the authorization URL in a browser (please substitute the CLIENTID and SECRET
with valid data):
----
https://sandbox.genesys-pgr.org/oauth/authorize?client_id=CLIENTID&client_secret=SECRET&response_type=code&redirect_uri=oob&scope=read%2Cwrite
https://sandbox.genesys-pgr.org/oauth/authorize?client_id=CLIENTID&client_secret=SECRET&response_type=code&redirect_uri=oob&scope=write
----
The server will prompt you to authorize the access to your protected resources on Genesys.
......@@ -63,7 +63,7 @@ Copy the authorization code: *THECODE* (looks like: 7wXP1r) and from shell, exec
$ curl 'https://sandbox.genesys-pgr.org/oauth/token?grant_type=authorization_code&client_id=CLIENTID&client_secret=SECRET&redirect_uri=oob&code=THECODE'
----
The server will respond with access token details in JSON format:
The server will respond with access token details in JSON format:
[source,json]
----
......@@ -76,7 +76,7 @@ The server will respond with access token details in JSON format:
}
----
You can use the access token to sign future HTTP requests to the API by adding a HTTP request header:
You can use the access token to sign future HTTP requests to the API by adding a HTTP request header:
[source,http]
----
......@@ -97,10 +97,20 @@ or include it in the request URL as a query string parameter:
$ curl 'https://sandbox.genesys-pgr.org/api/v0/me?access_token=OAUTH-ACCESS-TOKEN'
----
=== System-to-System integration
With Genesys release 2.3 the *Client authentication grant* is also supported. Kindly
contact the helpdesk@genesys-pgr.org for information how to enable system-to-system
integration and to grant your Client the appropriate permissions on Genesys.
**Note**: The client will be able to modify any data on Genesys on your behalf.
Read the section <<oauth, Client Credential Grant>>.
=== Using the refresh token
OAuth access tokens have a fairly short lifetime. When an access token expires, the
refresh token can be used to obtain a new access token. Refresh token is returned as
OAuth access tokens have a fairly short lifetime. When an access token expires, the
refresh token can be used to obtain a new access token. Refresh token is returned as
part of JSON response when verification code is used to obtain the access token:
[source,json]
......@@ -122,10 +132,9 @@ $ curl 'https://sandbox.genesys-pgr.org/oauth/token?grant_type=refresh_token&cli
----
== Client errors
The API returns descriptive information in the response body about why the request failed to execute.
The API returns descriptive information in the response body about why the request failed to execute.
=== 401 Unauthorized
......@@ -141,3 +150,9 @@ WWW-Authenticate: Bearer realm="genesys2", error="unauthorized", error_descripti
{"error":"unauthorized","error_description":"An Authentication object was not found in the SecurityContext"}
----
[bibliography]
- [[[doi]]] https://en.wikipedia.org
https://en.wikipedia.org/wiki/Digital_object_identifier[Digital object identifier].
- [[[oauth]]] A Bilbie
https://alexbilbie.com/guide-to-oauth-2-grants/[A Guide To OAuth 2.0 Grants].
package org.genesys2.hazelcast;
import java.io.IOException;
import org.genesys2.spring.config.SpringProperties;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.ActiveProfiles;
import com.hazelcast.config.Config;
import com.hazelcast.config.GroupConfig;
import com.hazelcast.config.JoinConfig;
import com.hazelcast.config.NetworkConfig;
import com.hazelcast.config.TcpIpConfig;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.ManagedContext;
import com.hazelcast.spring.context.SpringManagedContext;
public class HazelcastRunner {
@Configuration
@ActiveProfiles("dev")
@Import({ SpringProperties.class })
public static class AppConfig {
protected int hazelPort=5702;
@Value("${hazelcast.instanceName}")
protected String instanceName = "genesys";
@Value("${hazelcast.password}")
protected String password;
@Value("${hazelcast.name}")
protected String name;
@Bean
public Long number() {
return new Long(13);
}
@Bean
public ManagedContext managedContext() {
return new SpringManagedContext();
}
@Bean
public HazelcastInstance hazelcast(ManagedContext managedContext) {
Config cfg = new Config();
cfg.setManagedContext(managedContext);
cfg.setInstanceName(instanceName);
GroupConfig groupConfig = cfg.getGroupConfig();
groupConfig.setName(name);
groupConfig.setPassword(password);
cfg.setProperty("hazelcast.merge.first.run.delay.seconds", "5");
cfg.setProperty("hazelcast.merge.next.run.delay.seconds", "5");
cfg.setProperty("hazelcast.logging.type", "log4j");
cfg.setProperty("hazelcast.icmp.enabled", "true");
NetworkConfig network = cfg.getNetworkConfig();
network.setPort(hazelPort);
network.setPortAutoIncrement(true);
JoinConfig join = network.getJoin();
join.getMulticastConfig().setEnabled(false);
TcpIpConfig tcpIpConfig = join.getTcpIpConfig();
tcpIpConfig.setEnabled(true);
tcpIpConfig.setConnectionTimeoutSeconds(20);
// See if there's a local HZ running
tcpIpConfig.addMember("127.0.0.1:5701");
HazelcastInstance instance = Hazelcast.newHazelcastInstance(cfg);
return instance;
}
}
public static void main(String[] args) {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(AppConfig.class);
HazelcastInstance instance = ctx.getBean(HazelcastInstance.class);
System.out.println(instance);
System.out.println("Press any key to quit.");
try {
System.in.read();
} catch (IOException e) {
}
ctx.close();
}
}
......@@ -50,7 +50,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
@Configuration
@PropertySource("classpath:/spring/spring.properties")
@EnableJpaRepositories(basePackages = { "org.genesys.blocks.persistence", "org.genesys.blocks.security.persistence", "org.genesys.filerepository.persistence", "org.genesys2.server.persistence.acl", "org.genesys2.server.persistence.domain",
@EnableJpaRepositories(basePackages = { "org.genesys.blocks.persistence", "org.genesys.blocks.security.persistence","org.genesys.blocks.oauth.persistence", "org.genesys.filerepository.persistence", "org.genesys2.server.persistence.acl", "org.genesys2.server.persistence.domain",
"org.genesys2.server.filerepository.persistence" }, repositoryImplementationPostfix = "CustomImpl", entityManagerFactoryRef = "entityManagerFactory", transactionManagerRef = "transactionManager")
@EnableTransactionManagement
public class JpaDataConfig {
......@@ -80,7 +80,7 @@ public class JpaDataConfig {
bean.setDataSource(dataSource());
bean.setPersistenceUnitName("spring-jpa");
bean.setPackagesToScan("org.genesys.blocks.model", "org.genesys.blocks.security.model", "org.genesys2.server.model", "org.genesys.filerepository.model");
bean.setPackagesToScan("org.genesys.blocks.model", "org.genesys.blocks.security.model", "org.genesys.blocks.oauth.model", "org.genesys2.server.model", "org.genesys.filerepository.model");
bean.setPersistenceProvider(new HibernatePersistenceProvider());
final HibernateJpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter();
......
......@@ -26,6 +26,11 @@ import com.hazelcast.core.IQueue;
import org.apache.velocity.app.VelocityEngine;
import org.elasticsearch.common.collect.Sets;
import org.genesys.blocks.oauth.persistence.AccessTokenRepository;
import org.genesys.blocks.oauth.persistence.OAuthClientRepository;
import org.genesys.blocks.oauth.persistence.RefreshTokenRepository;
import org.genesys.blocks.oauth.service.OAuthClientDetailsService;
import org.genesys.blocks.oauth.service.OAuthServiceImpl;
import org.genesys.blocks.security.persistence.AclClassPersistence;
import org.genesys.blocks.security.persistence.AclEntryPersistence;
import org.genesys.blocks.security.persistence.AclObjectIdentityPersistence;
......@@ -61,9 +66,6 @@ import org.genesys2.server.persistence.domain.MaterialSubRequestRepository;
import org.genesys2.server.persistence.domain.MetadataMethodRepository;
import org.genesys2.server.persistence.domain.MetadataRepository;
import org.genesys2.server.persistence.domain.MethodRepository;
import org.genesys2.server.persistence.domain.OAuthAccessTokenPersistence;
import org.genesys2.server.persistence.domain.OAuthClientDetailsPersistence;
import org.genesys2.server.persistence.domain.OAuthRefreshTokenPersistence;
import org.genesys2.server.persistence.domain.OrganizationRepository;
import org.genesys2.server.persistence.domain.ParameterCategoryRepository;
import org.genesys2.server.persistence.domain.ParameterRepository;
......@@ -92,10 +94,8 @@ import org.genesys2.server.service.GeoService;
import org.genesys2.server.service.HtmlSanitizer;
import org.genesys2.server.service.InstituteFilesService;
import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.JPATokenStore;
import org.genesys2.server.service.KPIService;
import org.genesys2.server.service.MappingService;
import org.genesys2.server.service.OAuth2ClientDetailsService;
import org.genesys2.server.service.OrganizationService;
import org.genesys2.server.service.RequestService;
import org.genesys2.server.service.TaxonomyService;
......@@ -121,8 +121,6 @@ import org.genesys2.server.service.impl.InstituteFilesServiceImpl;
import org.genesys2.server.service.impl.InstituteServiceImpl;
import org.genesys2.server.service.impl.KPIServiceImpl;
import org.genesys2.server.service.impl.MappingServiceImpl;
import org.genesys2.server.service.impl.OAuth2ClientDetailsServiceImpl;
import org.genesys2.server.service.impl.OAuth2JPATokenStoreImpl;
import org.genesys2.server.service.impl.OWASPSanitizer;
import org.genesys2.server.service.impl.OrganizationServiceImpl;
import org.genesys2.server.service.impl.RequestServiceImpl;
......@@ -133,6 +131,7 @@ import org.genesys2.server.service.impl.TokenVerificationServiceImpl;
import org.genesys2.server.service.impl.UserServiceImpl;
import org.genesys2.server.service.worker.ElasticUpdater;
import org.genesys2.server.service.worker.GeoRegionDataCLDR;
import org.genesys2.server.servlet.controller.admin.OAuthManagementController;
import org.genesys2.server.servlet.controller.rest.AccessionController;
import org.genesys2.server.servlet.controller.rest.CacheController;
import org.genesys2.server.servlet.controller.rest.CropsController;
......@@ -140,11 +139,9 @@ import org.genesys2.server.servlet.controller.rest.DatasetController;
import org.genesys2.server.servlet.controller.rest.InstituteGalleriesController;
import org.genesys2.server.servlet.controller.rest.KPIController;
import org.genesys2.server.servlet.controller.rest.LookupController;
import org.genesys2.server.servlet.controller.rest.OAuthManagementController;
import org.genesys2.server.servlet.controller.rest.OrganizationController;
import org.genesys2.server.servlet.controller.rest.PermissionController;
import org.genesys2.server.servlet.controller.rest.RequestsController;
import org.genesys2.server.servlet.controller.rest.TokenController;
import org.genesys2.server.servlet.controller.rest.TraitsController;
import org.genesys2.server.servlet.controller.rest.UserController;
import org.genesys2.server.servlet.controller.rest.UsersController;
......@@ -165,7 +162,6 @@ import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.security.oauth2.provider.token.ConsumerTokenServices;
import org.springframework.security.oauth2.provider.token.DefaultTokenServices;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.HierarchyMode;
......@@ -310,10 +306,10 @@ public abstract class AbstractRestTest extends BaseSpringTest {
}
@Bean
public OAuth2ClientDetailsService auth2ClientDetailsService() {
return new OAuth2ClientDetailsServiceImpl();
public OAuthServiceImpl oauthService() {
return new OAuthServiceImpl();
}
@Bean
public EMailVerificationService emailVerificationService() {
return new EMailVerificationServiceImpl();
......@@ -404,23 +400,6 @@ public abstract class AbstractRestTest extends BaseSpringTest {
return new EasySMTAMockConnector();
}
@Bean
public TokenController tokenController() {
return new TokenController();
}
@Bean
public ConsumerTokenServices consumerTokenServices() {
DefaultTokenServices tokenServices = new DefaultTokenServices();
tokenServices.setTokenStore(tokenStore());
return tokenServices;
}
@Bean
public JPATokenStore tokenStore() {
return new OAuth2JPATokenStoreImpl();
}
@Bean
public OAuthManagementController oAuthManagementController() {
return new OAuthManagementController();
......@@ -573,29 +552,20 @@ public abstract class AbstractRestTest extends BaseSpringTest {
// OAuthManagementController oAuthManagementController;
@Autowired
protected OAuthAccessTokenPersistence accessTokenPersistence;
@Autowired
protected OAuthRefreshTokenPersistence refreshTokenPersistence;
protected AccessTokenRepository accessTokenPersistence;
@Autowired
protected OAuthClientDetailsPersistence clientDetailsPersistence;
protected RefreshTokenRepository refreshTokenPersistence;
@Autowired
protected OAuth2ClientDetailsService clientDetailsService;
protected OAuthClientRepository clientDetailsPersistence;
@Autowired
protected TokenController tokenController;
@Autowired
protected ConsumerTokenServices tokenServices;
protected OAuthClientDetailsService clientDetailsService;
@Autowired
protected TokenStore tokenStore;
@Autowired
protected ConsumerTokenServices consumerTokenServices;
@Autowired
protected EasySMTA easySMTAConnector;
......
/*
* Copyright 2016 Global Crop Diversity Trust
*
* 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.
*/
package org.genesys2.tests.resttests;
import static org.hamcrest.Matchers.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys.blocks.security.UserException;
import org.genesys.blocks.security.service.PasswordPolicy.PasswordPolicyException;
import org.genesys2.server.model.UserRole;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AccessionId;
import org.genesys2.server.model.genesys.Metadata;
import org.genesys2.server.model.genesys.MetadataMethod;
import org.genesys2.server.model.genesys.Method;
import org.genesys2.server.model.genesys.Parameter;
import org.genesys2.server.model.genesys.ParameterCategory;
import org.genesys2.server.model.genesys.Taxonomy2;
import org.genesys2.server.model.impl.Country;
import org.genesys2.server.model.impl.Crop;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.User;
import org.genesys2.server.model.oauth.OAuthClientDetails;
import org.genesys2.server.model.oauth.OAuthClientType;
import org.genesys2.server.model.oauth.OAuthRefreshToken;
import org.genesys2.server.servlet.controller.rest.AccessionController;
import org.genesys2.server.servlet.controller.rest.model.AccessionHeaderJson;
import org.genesys2.server.servlet.controller.rest.model.AccessionNamesJson;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.provider.DefaultAuthorizationRequest;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.token.DefaultTokenServices;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
@Ignore
public class AccessionControllerTest extends AbstractRestTest {
private static final Log LOG = LogFactory.getLog(AccessionControllerTest.class);
@Autowired
private WebApplicationContext webApplicationContext;
MockMvc mockMvc;
private Metadata metadata;
private FaoInstitute faoInstitute;
private List<FaoInstitute> institutes = new ArrayList<>();
private User user = new User();
private OAuth2AccessToken accessToken;
private OAuthRefreshToken refreshToken;
private OAuthClientDetails oAuthClientDetails;
private Method method;
private Crop crop;
private ParameterCategory category;
private Parameter parameter;
private MetadataMethod metadataMethod;
private Accession accession;
private Country country = new Country();
@Before
public void setup() throws UserException, JsonProcessingException, InterruptedException, PasswordPolicyException {
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
oAuthClientDetails = clientDetailsService.addClientDetails("title", "description", "redirectUri", 1, 2, OAuthClientType.SERVICE);
user = new User();
user.setEmail("salexandrbasov@gmail.com");
user.setPassword("Alexandr19011990");
user.setFullName("SYS_ADMIN");
userService.addUser(user);
faoInstitute = new FaoInstitute();
faoInstitute.setFullName("This is name of institute");
faoInstitute.setCurrent(true);
faoInstitute.setPgrActivity(true);
faoInstitute.setMaintainsCollection(true);
faoInstitute.setPgrActivity(true);
faoInstitute.setAccessionCount(1);
faoInstitute.setUniqueAcceNumbs(true);
faoInstitute.setCode("Code");
institutes.add(faoInstitute);
instituteService.update(institutes);
ObjectMapper objectMapper = new ObjectMapper();
crop = cropService.addCrop("shortName", "Name", "description", "en");
traitService.addCategory("nameOfParameterCategory", objectMapper.writeValueAsString("en"));
parameter = traitService.addParameter("rdfUri", crop, "nameOfParameterCategory", "titleOfParameter", objectMapper.writeValueAsString("en"));
method = traitService.addMethod("rdfUriMethod", "descriptionMethod", objectMapper.writeValueAsString("en"), "unitForMethod", "fieldName", 1, 2, "options", "range", parameter);
metadata = datasetService.addDataset(faoInstitute, "TitleMetaData", "Description metaData");
Map<Integer, Boolean> permission = new HashMap<>();
metadataMethod = new MetadataMethod();
metadataMethod.setMetadata(metadata);
metadataMethod.setMethodId(method.getId());
metadataMethodRepository.save(metadataMethod);
permission.put(4, true);
permission.put(1, false);
permission.put(2, false);
permission.put(8, false);
permission.put(16, true);
aclService.addPermissions(metadata.getId(), Metadata.class.getName(), "SYS_ADMIN", true, permission);
HashMap<String, String> authorizationParameters = new HashMap<String, String>();
authorizationParameters.put("scope", "read");
authorizationParameters.put("username", user.getEmail());
authorizationParameters.put("client_id", user.getEmail());
authorizationParameters.put("grant", user.getPassword());