From 838a5c3f1523054b760ba1f7803f9736c667cad7 Mon Sep 17 00:00:00 2001 From: ivy-jh Date: Wed, 28 Aug 2024 15:51:26 +0200 Subject: [PATCH] format codestyle java/html --- .../skribble/demo/LocalResource.java | 63 ++-- .../connector/skribble/demo/SampleHelper.java | 112 +++---- .../skribble/demo/Overview/Overview.xhtml | 248 ++++++++-------- .../demo/Overview/dlgDocumentViewer.xhtml | 10 +- .../demo/SignRequest/SignRequest.xhtml | 278 +++++++++--------- skribble-connector-product/README.md | 7 +- .../skribble/SkribbleAuthFeature.java | 96 +++--- .../openapi/bean/DateTimeHelperBean.java | 32 +- 8 files changed, 411 insertions(+), 435 deletions(-) diff --git a/skribble-connector-demo/src/com/axonivy/connector/skribble/demo/LocalResource.java b/skribble-connector-demo/src/com/axonivy/connector/skribble/demo/LocalResource.java index aa42178..bb6b532 100644 --- a/skribble-connector-demo/src/com/axonivy/connector/skribble/demo/LocalResource.java +++ b/skribble-connector-demo/src/com/axonivy/connector/skribble/demo/LocalResource.java @@ -8,40 +8,39 @@ import org.apache.commons.io.IOUtils; - /* * Loader for files from resources folder. */ -public class LocalResource{ - - private final String path; - - public LocalResource(String relativeFilePath){ - this.path = relativeFilePath; - } - - public Path asPath(){ - return asFile().toPath(); - } - - public File asFile(){ - try { - ch.ivyteam.ivy.scripting.objects.File file = new ch.ivyteam.ivy.scripting.objects.File(path, true); - file.createNewFile(); - - try (InputStream is = asStream()){ - String res = IOUtils.toString(is, StandardCharsets.ISO_8859_1); - file.write(res, StandardCharsets.ISO_8859_1.name()); - return file.getJavaFile(); - } - - }catch (IOException ex){ - throw new RuntimeException("Failed to load resource "+path, ex); - } - } - - private InputStream asStream(){ - return LocalResource.class.getResourceAsStream("/"+path); - } +public class LocalResource { + + private final String path; + + public LocalResource(String relativeFilePath) { + this.path = relativeFilePath; + } + + public Path asPath() { + return asFile().toPath(); + } + + public File asFile() { + try { + ch.ivyteam.ivy.scripting.objects.File file = new ch.ivyteam.ivy.scripting.objects.File(path, true); + file.createNewFile(); + + try (InputStream is = asStream()) { + String res = IOUtils.toString(is, StandardCharsets.ISO_8859_1); + file.write(res, StandardCharsets.ISO_8859_1.name()); + return file.getJavaFile(); + } + + } catch (IOException ex) { + throw new RuntimeException("Failed to load resource " + path, ex); + } + } + + private InputStream asStream() { + return LocalResource.class.getResourceAsStream("/" + path); + } } diff --git a/skribble-connector-demo/src/com/axonivy/connector/skribble/demo/SampleHelper.java b/skribble-connector-demo/src/com/axonivy/connector/skribble/demo/SampleHelper.java index be7a379..73cbd0e 100644 --- a/skribble-connector-demo/src/com/axonivy/connector/skribble/demo/SampleHelper.java +++ b/skribble-connector-demo/src/com/axonivy/connector/skribble/demo/SampleHelper.java @@ -9,60 +9,62 @@ import com.skribble.api.v2.client.SignerIdentityData; import com.skribble.api.v2.client.VisualSignature; -public class SampleHelper{ - - private static final float POSITION_HEIGH = 60; - private static final float POSITION_WIDTH = 160; - private static final String POSITION_PAGE = "0"; - - public static CreateSignatureRequest createSignatureRequestDocSample(String title, String message){ - CreateSignatureRequest csr = new CreateSignatureRequest(); - csr.setTitle(title); - csr.setMessage(message); - - try { - FileInputStream fis = new FileInputStream(new LocalResource("com/axonivy/connector/skribble/demo/docs/test.pdf").asFile()); - csr.setContent( Base64.getEncoder().encodeToString(fis.readAllBytes()) ); - - }catch(Exception e){ - return null; - } - - return csr; - } - - public static CreateSignature createSignature(String accountEmail, boolean notifiy){ - CreateSignature cs = new CreateSignature(); - cs.setAccountEmail(accountEmail); - cs.notify(notifiy); - - return cs; - } - - public static VisualSignature createVisualSignature(float positionX, float positionY){ - VisualSignature vs = new VisualSignature(); - vs.setPosition(SampleHelper.createPosition(positionX, positionY, POSITION_PAGE, POSITION_HEIGH, POSITION_WIDTH)); - - return vs; - } - - public static SignerIdentityData createSignerIdentityData(String email, String fistname, String lastname){ - SignerIdentityData si = new SignerIdentityData(); - si.setEmailAddress(email); - si.setFirstName(fistname); - si.setLastName(lastname); - - return si; - } - - private static Position createPosition(float x, float y, String page, float height, float width){ - Position po = new Position(); - po.setHeight(height); - po.setWidth(width); - po.setX(x); - po.setY(y); - po.setPage(page); - return po; - } +public class SampleHelper { + + private static final float POSITION_HEIGH = 60; + private static final float POSITION_WIDTH = 160; + private static final String POSITION_PAGE = "0"; + + public static CreateSignatureRequest createSignatureRequestDocSample(String title, String message) { + CreateSignatureRequest csr = new CreateSignatureRequest(); + csr.setTitle(title); + csr.setMessage(message); + + try { + FileInputStream fis = new FileInputStream( + new LocalResource("com/axonivy/connector/skribble/demo/docs/test.pdf").asFile()); + csr.setContent(Base64.getEncoder().encodeToString(fis.readAllBytes())); + + } catch (Exception e) { + return null; + } + + return csr; + } + + public static CreateSignature createSignature(String accountEmail, boolean notifiy) { + CreateSignature cs = new CreateSignature(); + cs.setAccountEmail(accountEmail); + cs.notify(notifiy); + + return cs; + } + + public static VisualSignature createVisualSignature(float positionX, float positionY) { + VisualSignature vs = new VisualSignature(); + vs.setPosition( + SampleHelper.createPosition(positionX, positionY, POSITION_PAGE, POSITION_HEIGH, POSITION_WIDTH)); + + return vs; + } + + public static SignerIdentityData createSignerIdentityData(String email, String fistname, String lastname) { + SignerIdentityData si = new SignerIdentityData(); + si.setEmailAddress(email); + si.setFirstName(fistname); + si.setLastName(lastname); + + return si; + } + + private static Position createPosition(float x, float y, String page, float height, float width) { + Position po = new Position(); + po.setHeight(height); + po.setWidth(width); + po.setX(x); + po.setY(y); + po.setPage(page); + return po; + } } diff --git a/skribble-connector-demo/src_hd/com/axonivy/connector/skribble/demo/Overview/Overview.xhtml b/skribble-connector-demo/src_hd/com/axonivy/connector/skribble/demo/Overview/Overview.xhtml index 5ce3cb7..d8e5a64 100644 --- a/skribble-connector-demo/src_hd/com/axonivy/connector/skribble/demo/Overview/Overview.xhtml +++ b/skribble-connector-demo/src_hd/com/axonivy/connector/skribble/demo/Overview/Overview.xhtml @@ -1,141 +1,137 @@ - + - - Overview - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + Overview + + + + + + + + + + + + + + + + - - - + + + - - - + + + - - - - + + + + + - - - + + + - - - - + + + + + + + + - - - - + + + + + + + - - - - - - - -
- - -
+ + -
-
+ + + - -
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/skribble-connector-demo/src_hd/com/axonivy/connector/skribble/demo/Overview/dlgDocumentViewer.xhtml b/skribble-connector-demo/src_hd/com/axonivy/connector/skribble/demo/Overview/dlgDocumentViewer.xhtml index 26af082..3b051a1 100644 --- a/skribble-connector-demo/src_hd/com/axonivy/connector/skribble/demo/Overview/dlgDocumentViewer.xhtml +++ b/skribble-connector-demo/src_hd/com/axonivy/connector/skribble/demo/Overview/dlgDocumentViewer.xhtml @@ -8,10 +8,12 @@ - - - + position="center center" width="80%" height="60%"> + + + + diff --git a/skribble-connector-demo/src_hd/com/axonivy/connector/skribble/demo/SignRequest/SignRequest.xhtml b/skribble-connector-demo/src_hd/com/axonivy/connector/skribble/demo/SignRequest/SignRequest.xhtml index 38672bc..2e07571 100644 --- a/skribble-connector-demo/src_hd/com/axonivy/connector/skribble/demo/SignRequest/SignRequest.xhtml +++ b/skribble-connector-demo/src_hd/com/axonivy/connector/skribble/demo/SignRequest/SignRequest.xhtml @@ -1,150 +1,136 @@ - + - - New Document - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + New Document + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - -
- -
-
- - -
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/skribble-connector-product/README.md b/skribble-connector-product/README.md index a3cc558..49fc97a 100644 --- a/skribble-connector-product/README.md +++ b/skribble-connector-product/README.md @@ -47,17 +47,14 @@ Before any signing interactions between the **Axon Ivy Engine** and the **Skribb ``` # == Variables == - # - # You can define here your project Variables. - # Variables: #set all paramaters for Skribble-connector skribbleConnector: #username - username: 'api_demo_xxxxx' #<-- paste here your username + username: 'api_demo_xxxxx' #<-- paste here your username #apikey #[password] - authKey: ${decrypt:\u00AF\u00A8...} #<-- paste here your apikey and encrypt it + authKey: ${decrypt:\u00AF\u00A8...} #<-- paste here your apikey and encrypt it ``` diff --git a/skribble-connector/src/com/axonivy/connector/skribble/SkribbleAuthFeature.java b/skribble-connector/src/com/axonivy/connector/skribble/SkribbleAuthFeature.java index c87eccc..48a1d3b 100644 --- a/skribble-connector/src/com/axonivy/connector/skribble/SkribbleAuthFeature.java +++ b/skribble-connector/src/com/axonivy/connector/skribble/SkribbleAuthFeature.java @@ -20,59 +20,55 @@ import ch.ivyteam.ivy.rest.client.FeatureConfig; public class SkribbleAuthFeature implements Feature { - - @Override - public boolean configure(FeatureContext context) { - context.register(new AuthFilter(), Priorities.AUTHENTICATION); - return true; - } - - private static class AuthFilter implements ClientRequestFilter { - - private static final String SKRIBBLE_AUTH_SESSION_TOKEN = "skribble.auth.sessionToken"; @Override - public void filter(ClientRequestContext ctxt) throws IOException { - if (ctxt.getUri().toASCIIString().contains("/login")) { - return; - } - - var sessionToken = (String) IApplication.current().getAttribute(SKRIBBLE_AUTH_SESSION_TOKEN); - - if (sessionToken != null) { - var decoded = new JWT().decodeJwt(sessionToken); - var expiry = decoded.getExpiresAtAsInstant(); - if (expiry.isBefore(Instant.now())) { - sessionToken = null; - } - } - - if(sessionToken == null) { - sessionToken = login(ctxt); - - IApplication.current().setAttribute(SKRIBBLE_AUTH_SESSION_TOKEN,sessionToken ); - - } - ctxt.getHeaders().putSingle("Authorization", "Bearer "+sessionToken); - } - - private String login(ClientRequestContext ctxt) { - - var config = new FeatureConfig(ctxt.getConfiguration(), SkribbleAuthFeature.class); - String key = config.readMandatory("AUTH.key"); - - var login = new AccessLoginBody(); - login.setApiKey(key); - login.setUsername(config.readMandatory("AUTH.username")); - - return Ivy.rest().client(UUID.fromString("6c92d3d7-cb33-4cfa-964a-8242ad165742")) - .path("v2/access/login").request() - .post(Entity.entity(login, MediaType.APPLICATION_JSON), String.class); + public boolean configure(FeatureContext context) { + context.register(new AuthFilter(), Priorities.AUTHENTICATION); + return true; } - - - } + private static class AuthFilter implements ClientRequestFilter { -} + private static final String SKRIBBLE_AUTH_SESSION_TOKEN = "skribble.auth.sessionToken"; + + @Override + public void filter(ClientRequestContext ctxt) throws IOException { + if (ctxt.getUri().toASCIIString().contains("/login")) { + return; + } + + var sessionToken = (String) IApplication.current().getAttribute(SKRIBBLE_AUTH_SESSION_TOKEN); + + if (sessionToken != null) { + var decoded = new JWT().decodeJwt(sessionToken); + var expiry = decoded.getExpiresAtAsInstant(); + if (expiry.isBefore(Instant.now())) { + sessionToken = null; + } + } + + if (sessionToken == null) { + sessionToken = login(ctxt); + + IApplication.current().setAttribute(SKRIBBLE_AUTH_SESSION_TOKEN, sessionToken); + } + ctxt.getHeaders().putSingle("Authorization", "Bearer " + sessionToken); + } + + private String login(ClientRequestContext ctxt) { + + var config = new FeatureConfig(ctxt.getConfiguration(), SkribbleAuthFeature.class); + String key = config.readMandatory("AUTH.key"); + + var login = new AccessLoginBody(); + login.setApiKey(key); + login.setUsername(config.readMandatory("AUTH.username")); + + return Ivy.rest().client(UUID.fromString("6c92d3d7-cb33-4cfa-964a-8242ad165742")).path("v2/access/login") + .request().post(Entity.entity(login, MediaType.APPLICATION_JSON), String.class); + } + + } + +} diff --git a/skribble-connector/src/com/skribble/openapi/bean/DateTimeHelperBean.java b/skribble-connector/src/com/skribble/openapi/bean/DateTimeHelperBean.java index 515fe9d..6ced8a2 100644 --- a/skribble-connector/src/com/skribble/openapi/bean/DateTimeHelperBean.java +++ b/skribble-connector/src/com/skribble/openapi/bean/DateTimeHelperBean.java @@ -1,6 +1,5 @@ package com.skribble.openapi.bean; - import java.util.Date; import javax.faces.bean.ManagedBean; @@ -8,22 +7,21 @@ import ch.ivyteam.ivy.environment.Ivy; - @ViewScoped @ManagedBean -public class DateTimeHelperBean{ - - public static Date getJavaDate(String instantStr) { - - Date date = null; - try { - date = Date.from(java.time.Instant.parse(instantStr)); - - }catch(Exception e){ - return null; - } - - return date; - - } +public class DateTimeHelperBean { + + public static Date getJavaDate(String instantStr) { + + Date date = null; + try { + date = Date.from(java.time.Instant.parse(instantStr)); + + } catch (Exception e) { + return null; + } + + return date; + + } }