How to use getRootDirectory method of com.testsigma.service.OnPremiseStorageService class

Best Testsigma code snippet using com.testsigma.service.OnPremiseStorageService.getRootDirectory

Source:OnPremiseStorageService.java Github

copy

Full Screen

...33 this.jwtTokenService = jwtTokenService;34 }35 private String getFilePathRelativeToRoot(String filePath) {36 if (!filePath.trim().toLowerCase().startsWith(FILE_PROTOCOL)) {37 String root = getRootDirectory();38 if (root.contains("\\") || root.contains("\\\\")) {39 filePath = String.valueOf(root.charAt(root.length() - 1)).equals("\\") ? root +40 filePath.replaceAll("/", "\\\\").substring(1) : root + filePath.replaceAll("/", "\\\\");41 filePath = filePath.substring(0, 8) + filePath.substring(8).replaceAll ("\\\\\\\\", "\\\\");42 } else43 filePath = root + File.separator + filePath;44 } else {45 filePath = filePath.substring(5);46 }47 return filePath;48 }49 @Override50 public void addFile(String filePathToAdd, File fileToAdd) {51 String filePathFromRoot = getFilePathRelativeToRoot(filePathToAdd);52 log.info(String.format("Copying file from %s to %s", fileToAdd, filePathFromRoot));53 File newFile = new File(filePathFromRoot);54 try {55 if (newFile.exists()) {56 FileUtils.forceDeleteOnExit(newFile);57 }58 FileUtils.copyFile(fileToAdd, newFile);59 } catch (IOException e) {60 log.error("Unable to create a new file", e);61 }62 }63 @Override64 public void addFile(String filePathToAdd, InputStream inputStream) {65 String filePathFromRoot = getFilePathRelativeToRoot(filePathToAdd);66 log.info(String.format("Copying data from input stream to %s", filePathFromRoot));67 File newFile = new File(filePathFromRoot);68 try {69 if (newFile.exists()) {70 FileUtils.forceDelete(newFile);71 }72 FileUtils.copyInputStreamToFile(inputStream, new File(filePathFromRoot));73 } catch (IOException e) {74 log.error("Unable to create a new file from input stream", e);75 }76 }77 public void addDirectory(String directoryPathFromRoot) {78 File newDir = new File(getFilePathRelativeToRoot(directoryPathFromRoot));79 try {80 FileUtils.forceMkdir(newDir);81 } catch (IOException e) {82 log.error("Unable to create a new directory", e);83 }84 }85 @Override86 public URL generatePreSignedURL(String relativeFilePathFromBase, StorageAccessLevel storageAccessLevel, Integer expiryTimeInMinutes) {87 log.info("Generating pre-signed URL for:" + relativeFilePathFromBase);88 Calendar cal = Calendar.getInstance();89 cal.add(Calendar.MINUTE, expiryTimeInMinutes);90 URL preSignedURL = null;91 try {92 String token = jwtTokenService.generateAttachmentToken(relativeFilePathFromBase, cal.getTime(), getHttpMethod(storageAccessLevel));93 MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<>();94 queryParams.add(STORAGE_SIGNATURE, token);95 if (relativeFilePathFromBase.contains("\\") || relativeFilePathFromBase.contains("\\\\") )96 relativeFilePathFromBase = relativeFilePathFromBase.replaceAll("\\\\", "/");97 relativeFilePathFromBase = relativeFilePathFromBase.replaceAll("\\\\\\\\", "/");98 UriComponents uriComponents =99 UriComponentsBuilder.fromUriString(URLConstants.PRESIGNED_BASE_URL + "/{key}").queryParams(queryParams)100 .build().expand(relativeFilePathFromBase).encode();101 preSignedURL = new URL(applicationConfig.getServerUrl() + uriComponents.toUriString());102 log.info("Before normalizing - " + preSignedURL.toString());103 preSignedURL = preSignedURL.toURI().normalize().toURL();104 log.info("After normalizing - " + preSignedURL.toString());105 } catch (Exception e) {106 log.error("Unable to construct pre-signed URL object from path," + relativeFilePathFromBase, e);107 }108 return preSignedURL;109 }110 @Override111 public Optional<URL> generatePreSignedURLIfExists(String relativeFilePathFromBase, StorageAccessLevel storageAccessLevel, Integer expiryTimeInMinutes) {112 log.debug("Generating File URL if exists:" + relativeFilePathFromBase);113 Optional<URL> returnURL = Optional.empty();114 String rootDirectory = getRootDirectory();115 if (rootDirectory.contains("\\") || rootDirectory.contains("\\\\") ){116 String lastChar = String.valueOf(rootDirectory.charAt(rootDirectory.length() - 1));117 relativeFilePathFromBase = lastChar.equals("\\") || lastChar.equals("\\\\") ?118 relativeFilePathFromBase.replaceAll("/", "\\\\").substring(1) :119 relativeFilePathFromBase.replaceAll("/", "\\\\");120 }121 File file = Paths.get(rootDirectory, relativeFilePathFromBase).toFile();122 if (file.exists()) {123 log.debug("File exists, generating pre-signed URL for:" + relativeFilePathFromBase);124 returnURL = Optional.ofNullable(generatePreSignedURL(relativeFilePathFromBase, storageAccessLevel, expiryTimeInMinutes));125 }126 return returnURL;127 }128 @Override129 public Optional<URL> generatePreSignedURLIfExists(String relativeFilePathFromBase, StorageAccessLevel storageAccessLevel) {130 return generatePreSignedURLIfExists(relativeFilePathFromBase, storageAccessLevel, 600);131 }132 @Override133 public URL generatePreSignedURL(String relativeFilePathFromBase, StorageAccessLevel storageAccessLevel) {134 return generatePreSignedURL(relativeFilePathFromBase, storageAccessLevel, 600);135 }136 @Override137 public String downloadToLocal(String relativeFilePathFromBase, StorageAccessLevel storageAccessLevel) throws TestsigmaException {138 return getRootDirectory() + File.separator + relativeFilePathFromBase;139 }140 @Override141 public void deleteFile(String filePath) {142 FileUtils.deleteQuietly(new File(filePath));143 }144 @Override145 protected String getRootDirectory() {146 return Paths.get(applicationConfig.getDataDir(), storageConfig.getOnPremiseRootDirectory()).toString();147 }148 public String getAbsoluteFilePath(String relativePathFromRoot) {149 return getRootDirectory() + File.separator + relativePathFromRoot;150 }151 private HttpMethod getHttpMethod(StorageAccessLevel storageAccessLevel) {152 switch (storageAccessLevel) {153 case WRITE:154 case FULL_ACCESS:155 return HttpMethod.POST;156 case DELETE:157 return HttpMethod.DELETE;158 default:159 return HttpMethod.GET;160 }161 }162}...

Full Screen

Full Screen

getRootDirectory

Using AI Code Generation

copy

Full Screen

1com.testsigma.service.OnPremiseStorageService service = new com.testsigma.service.OnPremiseStorageService();2String rootDirectory = service.getRootDirectory();3com.testsigma.service.OnPremiseStorageService service = new com.testsigma.service.OnPremiseStorageService();4String rootDirectory = service.getRootDirectory();5C:\Program Files (x86)\TestSigma\bin\lib\com\testsigma\service6C:\Program Files (x86)\TestSigma\bin\lib\com\testsigma\service7C:\Program Files (x86)\TestSigma\bin\lib\com\testsigma\service8C:\Program Files (x86)\TestSigma\bin\lib\com\testsigma\service9C:\Program Files (x86)\TestSigma\bin\lib\com

Full Screen

Full Screen

getRootDirectory

Using AI Code Generation

copy

Full Screen

1import com.testsigma.service.OnPremiseStorageService2def storageService = new OnPremiseStorageService()3def rootDir = storageService.getRootDirectory()4def newDir = new File(rootDir, "newDirectory")5newDir.mkdir()6def newFile = new File(newDir, "newFile.txt")7newFile.createNewFile()8newFile.write("This is a new file created by TestSigma")9newFile.delete()10newDir.delete()11def newDir2 = new File(rootDir, "newDirectory2")12newDir2.mkdir()13def newFile2 = new File(newDir2, "newFile2.txt")14newFile2.createNewFile()15newFile2.write("This is a new file created by TestSigma")16newFile2.delete()17newDir2.delete()18def newDir3 = new File(rootDir, "newDirectory3")19newDir3.mkdir()20def newFile3 = new File(newDir3, "newFile3.txt")21newFile3.createNewFile()22newFile3.write("This is a new file created by TestSigma")

Full Screen

Full Screen

getRootDirectory

Using AI Code Generation

copy

Full Screen

1import com.testsigma.service.OnPremiseStorageService2def rootDirectory = OnPremiseStorageService.getRootDirectory()3import com.testsigma.service.OnPremiseStorageService4def directory = OnPremiseStorageService.getDirectory("testData")5import com.testsigma.service.OnPremiseStorageService6def directory = OnPremiseStorageService.getDirectory("testData", "parentTestData")7import com.testsigma.service.OnPremiseStorageService8def directory = OnPremiseStorageService.getDirectory("testData", "parentTestData", "grandParentTestData")9import com.testsigma.service.OnPremiseStorageService10def directory = OnPremiseStorageService.getDirectory("testData", "parentTestData", "grandParentTestData", "greatGrandParentTestData")

Full Screen

Full Screen

getRootDirectory

Using AI Code Generation

copy

Full Screen

1var onPremiseStorageService = new com.testsigma.service.OnPremiseStorageService();2var rootDirectory = onPremiseStorageService.getRootDirectory();3console.log(rootDirectory);4var onPremiseStorageService = new com.testsigma.service.OnPremiseStorageService();5var rootDirectory = onPremiseStorageService.getRootDirectory();6console.log(rootDirectory);

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testsigma automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful