Skip to content

Commit

Permalink
format codestyle java/html
Browse files Browse the repository at this point in the history
  • Loading branch information
ivy-jh committed Aug 28, 2024
1 parent f121368 commit 838a5c3
Show file tree
Hide file tree
Showing 8 changed files with 411 additions and 435 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
Loading

0 comments on commit 838a5c3

Please sign in to comment.