code format

This commit is contained in:
Alfredo Oliviero 2024-02-26 10:11:45 +01:00
parent 051c448e87
commit 2fc47d8d21
13 changed files with 218 additions and 189 deletions

12
.vscode/settings.json vendored
View File

@ -8,5 +8,15 @@
"debug": false
}
],
"java.dependency.packagePresentation": "hierarchical"
"java.dependency.packagePresentation": "hierarchical",
"Workspace_Formatter.excludePattern": [
"**/build",
"**/.*",
"**/.vscode",
"**/docs/*",
"**/documentazione/*",
"**/target/*",
"**/tomcat/*",
"**/webapps/*"
]
}

View File

@ -1,20 +1,19 @@
<configuration scan="true" debug="true">
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>Ï
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
<encoder>Ï <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<logger name="org.gcube" level="DEBUG" />
<logger name="org.gcube.smartgears" level="TRACE" />
<logger name="org.gcube.smartgears.handlers" level="TRACE"/>
<logger name="org.gcube.smartgears.handlers" level="TRACE" />
<logger name="org.gcube.common.events" level="WARN" />
<logger name="org.gcube.data.publishing" level="ERROR" />
<logger name="org.gcube.documentstore" level="ERROR" />
<logger name="org.gcube.common.core.publisher.is.legacy" level="TRACE" />
<logger name="org.gcube.data.access" level="TRACE" />
<logger name="org.gcube.data.access.storagehub.handlers" level="DEBUG"/>
<logger name="org.gcube.data.access.storagehub.handlers" level="DEBUG" />
<root level="WARN">
<appender-ref ref="STDOUT" />

View File

@ -91,7 +91,7 @@ on instances.
| Operation | HTTP Method | URL | Success HTTP Status | Safe | Idempotent |
|-----------|-------------|-----|---------------------|------|------------|
| ------------------------------ | ----------- | -------------------------------------- | ------------------- | ---- | ---------- |
| **Supported<br/>HTTP Methods** | OPTIONS | /{COLLECTION} | 204 No Content | Y | Y |
| **List** | GET | /{COLLECTION} | 200 OK | Y | Y |
| **Count** | GET | /{COLLECTION}?count=true | 200 OK | Y | Y |

View File

@ -2,7 +2,7 @@
<enunciate
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://enunciate.webcohesion.com/schemas/enunciate-2.14.0.xsd">
<description package="org.gcube.acme.rest"/>
<description package="org.gcube.acme.rest" />
<api-classes>
<include pattern="org.gcube.acme.rest.*" />
<exclude pattern="org.gcube.acme.*" />
@ -15,7 +15,8 @@
<javascript-client disabled="true" />
<docs docsDir="${project.build.directory}" docsSubdir="api-docs" />
<swagger basePath="/${project.artifactId}" />
<docs freemarkerTemplate="${project.basedir}/src/main/resources/META-INF/enunciate/d4science_docs.fmt">
<docs
freemarkerTemplate="${project.basedir}/src/main/resources/META-INF/enunciate/d4science_docs.fmt">
<additional-css
file="css/d4science_enunciate_custom.css" />
</docs>

View File

@ -1,8 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0"
metadata-complete="true">
<display-name>Identity Manager Service</display-name>

View File

@ -6,7 +6,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Alfredo Oliviero (ISTI - CNR)
* @author Alfredo gOliviero (ISTI - CNR)
*/
public class IdentityManagerApplicationManager implements ApplicationManager {
@ -31,8 +31,8 @@ public class IdentityManagerApplicationManager implements ApplicationManager {
+ "-------------------------------------------------------",
context);
// ApplicationContext applicationContext = ContextProvider.get();
// String helloWorldEServiceID = applicationContext.id();
// ApplicationContext applicationContext = ContextProvider.get();
// String helloWorldEServiceID = applicationContext.id();
logger.trace(
"\n-------------------------------------------------------\n"
@ -40,15 +40,13 @@ public class IdentityManagerApplicationManager implements ApplicationManager {
+ "-------------------------------------------------------",
context);
}
/**
* {@inheritDoc}
*/
@Override
public synchronized void onShutdown(){
public synchronized void onShutdown() {
String context = SecretManagerProvider.get().getContext();
@ -58,7 +56,6 @@ public class IdentityManagerApplicationManager implements ApplicationManager {
+ "-------------------------------------------------------",
context);
logger.trace(
"\n-------------------------------------------------------\n"
+ "Identity Manager Service Stopped Successfully on context {}\n"

View File

@ -13,115 +13,138 @@ public class UsersRest {
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(Users.class);
/*
// @GET
// @Path("/get-usernames-by-role")
// @Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" })
public Response getUsernamesByRole(
@QueryParam("role-name") String roleName) {
Status status = Status.OK;
ResponseBean responseBean = new ResponseBean();
List<String> usernames = new ArrayList<String>();
try {
String ctx = SecretManagerProvider.get().getContext();
KeycloakApiClient keycloackApiClient = KeycloakAPIFactory.getSingleton().createtKeycloakInstance(ctx);
List<UserRepresentation> users = null; // searchByRole(keycloackApiClient, roleName);
if (users != null) {
for (UserRepresentation user : users) {
usernames.add(user.getUsername());
}
}
responseBean.setResult(usernames);
responseBean.setSuccess(true);
} catch (Exception e) {
logger.error("Unable to retrieve user with the requested role", e);
responseBean.setMessage(e.getMessage());
status = Status.INTERNAL_SERVER_ERROR;
}
return Response.status(status).entity(responseBean).build();
}
private static List<UserRepresentation> searchByRole(KeycloackApiClient keycloackApiClient, String roleName) {
logger.info("Searching by role: {}", roleName);
List<ClientRepresentation> clients = keycloackApiClient.kclient.realm(keycloackApiClient.realmName)
.clients().findByClientId(keycloackApiClient.clientIdContext);
String id = "";
for (ClientRepresentation client : clients) {
logger.info("found client =" + client.getClientId());
logger.info("found client id=" + client.getId());
id = client.getId();
}
List<UserRepresentation> users = keycloackApiClient.kclient.realm(keycloackApiClient.realmName)
.clients()
.get(id).roles().get(roleName)
.getUserMembers(0, 100000);
return users;
}
@GET
@Path("/{get-profile}")
@Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" })
public String getCurrentProfile() {
// SMARTGEARS Specializza il tracciamento della chiamata su Accounting
InnerMethodName.instance.set("getCurrentProfile");
Owner owner = SecretManagerProvider.get().getOwner();
ApplicationContext appContext = ContextProvider.get();
SimpleCredentials credentials = ((DefaultAuthorizationProvider) appContext.container().authorizationProvider())
.getCredentials();
String ctx = SecretManagerProvider.get().getContext();
KeycloackApiClient keycloackApiClient = KeycloakAPIFactory.getSingleton().createtKeycloakInstance(ctx);
return null;
}
@GET
@Path("/{get-email}")
@Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" })
public String getCurrentEmail() {
throw new NotImplementedYetException();
}
@GET
@Path("/{get-fullname}")
@Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" })
public String getCurrentFullname() {
throw new NotImplementedYetException();
}
@GET
@Path("/{get-all-usernames}")
@Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" })
public String getAllUsernames() {
throw new NotImplementedYetException();
}
@GET
@Path("/{get-all-fullnames-and-usernames}")
@Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" })
public String getAllUsernamesFullnames() {
throw new NotImplementedYetException();
}
@GET
@Path("/{user-exists}")
@Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" })
public boolean checkUserExists() {
throw new NotImplementedYetException();
}
@GET
@Path("/{get-oauth-profile}")
@Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" })
public boolean getCurrentOAuthProfile() {
throw new NotImplementedYetException();
}
* // @GET
* // @Path("/get-usernames-by-role")
* // @Produces({ "application/json;charset=UTF-8", "application/vnd.api+json"
* })
* public Response getUsernamesByRole(
*
* @QueryParam("role-name") String roleName) {
* Status status = Status.OK;
* ResponseBean responseBean = new ResponseBean();
*
* List<String> usernames = new ArrayList<String>();
* try {
* String ctx = SecretManagerProvider.get().getContext();
* KeycloakApiClient keycloackApiClient =
* KeycloakAPIFactory.getSingleton().createtKeycloakInstance(ctx);
*
* List<UserRepresentation> users = null; // searchByRole(keycloackApiClient,
* roleName);
* if (users != null) {
* for (UserRepresentation user : users) {
* usernames.add(user.getUsername());
* }
* }
* responseBean.setResult(usernames);
* responseBean.setSuccess(true);
* } catch (Exception e) {
* logger.error("Unable to retrieve user with the requested role", e);
* responseBean.setMessage(e.getMessage());
* status = Status.INTERNAL_SERVER_ERROR;
* }
*
* return Response.status(status).entity(responseBean).build();
*
* }
*
* private static List<UserRepresentation> searchByRole(KeycloackApiClient
* keycloackApiClient, String roleName) {
* logger.info("Searching by role: {}", roleName);
*
* List<ClientRepresentation> clients =
* keycloackApiClient.kclient.realm(keycloackApiClient.realmName)
* .clients().findByClientId(keycloackApiClient.clientIdContext);
*
* String id = "";
* for (ClientRepresentation client : clients) {
* logger.info("found client =" + client.getClientId());
* logger.info("found client id=" + client.getId());
* id = client.getId();
* }
*
* List<UserRepresentation> users =
* keycloackApiClient.kclient.realm(keycloackApiClient.realmName)
* .clients()
* .get(id).roles().get(roleName)
* .getUserMembers(0, 100000);
* return users;
* }
*
* @GET
*
* @Path("/{get-profile}")
*
* @Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" })
* public String getCurrentProfile() {
* // SMARTGEARS Specializza il tracciamento della chiamata su Accounting
* InnerMethodName.instance.set("getCurrentProfile");
* Owner owner = SecretManagerProvider.get().getOwner();
*
* ApplicationContext appContext = ContextProvider.get();
* SimpleCredentials credentials = ((DefaultAuthorizationProvider)
* appContext.container().authorizationProvider())
* .getCredentials();
*
* String ctx = SecretManagerProvider.get().getContext();
* KeycloackApiClient keycloackApiClient =
* KeycloakAPIFactory.getSingleton().createtKeycloakInstance(ctx);
* return null;
* }
*
* @GET
*
* @Path("/{get-email}")
*
* @Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" })
* public String getCurrentEmail() {
* throw new NotImplementedYetException();
* }
*
* @GET
*
* @Path("/{get-fullname}")
*
* @Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" })
* public String getCurrentFullname() {
* throw new NotImplementedYetException();
* }
*
* @GET
*
* @Path("/{get-all-usernames}")
*
* @Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" })
* public String getAllUsernames() {
* throw new NotImplementedYetException();
* }
*
* @GET
*
* @Path("/{get-all-fullnames-and-usernames}")
*
* @Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" })
* public String getAllUsernamesFullnames() {
* throw new NotImplementedYetException();
* }
*
* @GET
*
* @Path("/{user-exists}")
*
* @Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" })
* public boolean checkUserExists() {
* throw new NotImplementedYetException();
* }
*
* @GET
*
* @Path("/{get-oauth-profile}")
*
* @Produces({ "application/json;charset=UTF-8", "application/vnd.api+json" })
* public boolean getCurrentOAuthProfile() {
* throw new NotImplementedYetException();
* }
*/
}

View File

@ -1,4 +1,5 @@
package org.gcube.rest;
import java.io.Serializable;
/**
@ -68,4 +69,3 @@ public class ResponseBean implements Serializable {
+ ", message=" + message + ", result=" + result + "]";
}
}

View File

@ -10,7 +10,7 @@ import javax.ws.rs.HttpMethod;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@Target({ElementType.METHOD})
@Target({ ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@HttpMethod("PATCH")
public @interface PATCH {

View File

@ -10,7 +10,7 @@ import javax.ws.rs.HttpMethod;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@Target({ElementType.METHOD})
@Target({ ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@HttpMethod("PURGE")
public @interface PURGE {

View File

@ -21,9 +21,9 @@ public class HTTPUtility {
public static StringBuilder getStringBuilder(InputStream inputStream) throws IOException {
StringBuilder result = new StringBuilder();
try(BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
String line;
while((line = reader.readLine()) != null) {
while ((line = reader.readLine()) != null) {
result.append(line);
}
}
@ -33,7 +33,7 @@ public class HTTPUtility {
public static String getResultAsString(HttpURLConnection httpURLConnection) throws IOException {
int responseCode = httpURLConnection.getResponseCode();
if(responseCode >= Status.BAD_REQUEST.getStatusCode()) {
if (responseCode >= Status.BAD_REQUEST.getStatusCode()) {
Status status = Status.fromStatusCode(responseCode);
InputStream inputStream = httpURLConnection.getErrorStream();
StringBuilder result = getStringBuilder(inputStream);