Best SeLion code snippet using com.paypal.selion.grid.servlets.transfer.ManagedArtifactRepository.getManagedArtifact
Source:ManagedArtifactRepository.java
...86 LOGGER.entering(uploadedArtifact);87 File file = createFileUsing(uploadedArtifact);88 try {89 FileUtils.writeByteArrayToFile(file, uploadedArtifact.getArtifactContents());90 ManagedArtifact managedArtifact = getManagedArtifact(file.getAbsolutePath());91 LOGGER.exiting(managedArtifact);92 return managedArtifact;93 } catch (IOException e) {94 throw new ArtifactUploadException("IOException in writing file contents", e);95 }96 }97 }98 public ManagedArtifact getArtifact(String pathInfo) {99 LOGGER.entering(pathInfo);100 try {101 repositorySynchronizationLock.lock();102 ManagedArtifact managedArtifact = getMatchedArtifact(pathInfo);103 if (managedArtifact.isExpired()) {104 throw new ArtifactDownloadException("The requested artifact: " + managedArtifact.getArtifactName()105 + " has expired");106 }107 LOGGER.exiting(managedArtifact);108 return managedArtifact;109 } finally {110 repositorySynchronizationLock.unlock();111 }112 }113 private String getMutex(UploadedArtifact uploadedArtifact) {114 StringBuilder buffer = new StringBuilder();115 for (String s : uploadedArtifact.getMetaInfo().keySet()) {116 buffer.append(s);117 }118 return buffer.toString().intern();119 }120 private ManagedArtifact getMatchedArtifact(String pathInfo) {121 List<File> files = (List<File>) FileUtils.listFiles(repoFolder, TrueFileFilter.INSTANCE,122 TrueFileFilter.INSTANCE);123 for (File file : files) {124 ManagedArtifact managedArtifact = getManagedArtifact(file.getAbsolutePath());125 if (managedArtifact.matchesPathInfo(pathInfo)) {126 return managedArtifact;127 }128 }129 throw new ArtifactDownloadException("No artifact found for requested path: " + pathInfo);130 }131 private File createFileUsing(UploadedArtifact uploadedArtifact) {132 try {133 ManagedArtifact instance = getConfiguredManagedArtifactClass().newInstance();134 instance.initFromUploadedArtifact(uploadedArtifact);135 String pathInfo = instance.getAbsolutePath();136 File file = new File(pathInfo);137 File dir = new File(file.getParent());138 dir.mkdirs();139 if (!(file.exists() || file.createNewFile())) {140 throw new ArtifactUploadException("Cannot create file with name: " + file.getName());141 }142 return file;143 } catch (IOException | IllegalAccessException | InstantiationException e) {144 throw new ArtifactUploadException(e.getClass().getSimpleName() + " in creating file.", e);145 }146 }147 @SuppressWarnings("unchecked")148 public Class<? extends ManagedArtifact> getConfiguredManagedArtifactClass() {149 LOGGER.entering();150 try {151 String managedArtifactClassName = ConfigParser.parse().getString(ARTIFACT_CONFIG_PROPERTY);152 if (LOGGER.isLoggable(Level.FINE)) {153 LOGGER.log(Level.FINE, "ManagedArtifact class name configured in grid: " + managedArtifactClassName);154 }155 Class<? extends ManagedArtifact> managedArtifactClass = (Class<? extends ManagedArtifact>) this.getClass()156 .getClassLoader().loadClass(managedArtifactClassName);157 LOGGER.exiting(managedArtifactClass.getName());158 return managedArtifactClass;159 } catch (Exception exe) {160 throw new ArtifactUploadException(exe.getClass().getSimpleName() + " in creating ManagedArtifact: "161 + ConfigParser.parse().getString(ARTIFACT_CONFIG_PROPERTY), exe);162 }163 }164 private ManagedArtifact getManagedArtifact(String pathName) {165 try {166 ManagedArtifact managedArtifact = getConfiguredManagedArtifactClass().newInstance();167 managedArtifact.initFromPath(pathName);168 return managedArtifact;169 } catch (IllegalAccessException | InstantiationException e) {170 throw new ArtifactUploadException(e.getClass().getSimpleName() + " in creating ManagedArtifact: "171 + ConfigParser.parse().getString(ARTIFACT_CONFIG_PROPERTY), e);172 }173 }174 public File getRepositoryFolder() {175 return repoFolder;176 }177 /**178 * RepositoryCleaner cleans repository every hour. Recursively finds directories that are empty and deletes it.179 */180 private class RepositoryCleaner extends TimerTask {181 public void run() {182 try {183 repositorySynchronizationLock.lock();184 deleteExpiredFiles();185 deleteEmptyDirectories(repoFolder);186 } finally {187 repositorySynchronizationLock.unlock();188 }189 }190 private void deleteExpiredFiles() {191 List<File> files = (List<File>) FileUtils.listFiles(repoFolder, TrueFileFilter.INSTANCE,192 TrueFileFilter.INSTANCE);193 for (File file : files) {194 ManagedArtifact managedArtifact = getManagedArtifact(file.getAbsolutePath());195 if (managedArtifact.isExpired() && !file.delete()) {196 LOGGER.log(Level.WARNING, "File: " + file.getName() + " not deleted from repository");197 }198 }199 }200 private void deleteEmptyDirectories(File directory) {201 if (directory == null) {202 return;203 }204 File[] files = directory.listFiles();205 if (files == null) {206 return;207 }208 for (File file : files) {...
getManagedArtifact
Using AI Code Generation
1ManagedArtifactRepository managedArtifactRepository = new ManagedArtifactRepository();2ManagedArtifact managedArtifact = managedArtifactRepository.getManagedArtifact("artifactId");3File artifact = managedArtifact.getArtifact();4String artifactName = managedArtifact.getArtifactName();5String artifactPath = managedArtifact.getArtifactPath();6String artifactId = managedArtifact.getArtifactId();7long artifactSize = managedArtifact.getArtifactSize();8String artifactType = managedArtifact.getArtifactType();9String artifactUrl = managedArtifact.getArtifactUrl();10String artifactVersion = managedArtifact.getArtifactVersion();11String artifactGroupId = managedArtifact.getArtifactGroupId();12long artifactLastModifiedTime = managedArtifact.getArtifactLastModifiedTime();13Date artifactLastModifiedDate = managedArtifact.getArtifactLastModifiedDate();14String artifactLastModifiedDateInString = managedArtifact.getArtifactLastModifiedDateInString();15String artifactLastModifiedDateInString = managedArtifact.getArtifactLastModifiedDateInString("yyyy-MM-dd HH:mm:ss");16String artifactLastModifiedDateInString = managedArtifact.getArtifactLastModifiedDateInString("yyyy-MM-dd HH:mm:ss", Locale.US);17String artifactLastModifiedDateInString = managedArtifact.getArtifactLastModifiedDateInString("yyyy-MM-dd HH:mm:ss", Locale.US, TimeZone.getTimeZone("GMT"));18long artifactCreationTime = managedArtifact.getArtifactCreationTime();19Date artifactCreationDate = managedArtifact.getArtifactCreationDate();20String artifactCreationDateInString = managedArtifact.getArtifactCreationDateInString();21String artifactCreationDateInString = managedArtifact.getArtifactCreationDateInString("yyyy-MM-dd HH:mm:ss");22String artifactCreationDateInString = managedArtifact.getArtifactCreationDateInString("yyyy-MM-dd HH:mm:ss", Locale.US);
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!