Best Testsigma code snippet using com.testsigma.service.UploadVersionService.updateUploadWithLatestUploadVersion
Source:UploadVersionService.java
...107 log.error(e.getMessage(), e);108 throw new TestsigmaException(e.getMessage(), e);109 }110 }111 private void updateUploadWithLatestUploadVersion(UploadVersion uploadVersion,112 Long uploadId) throws TestsigmaException {113 Upload upload = uploadService.findById(uploadId);114 upload.setLatestVersionId(uploadVersion.getId());115 upload.setLatestVersion(uploadVersion);116 uploadService.update(upload);117 }118 private void uploadToStorage(String filePathInStorageService, File fileToUpload, UploadVersion upload) {119 try {120 log.info(String.format("Uploading file:%s to storage path %s", fileToUpload.getAbsolutePath(), filePathInStorageService));121 storageServiceFactory.getStorageService().addFile(filePathInStorageService, fileToUpload);122 upload.setUploadStatus(UploadStatus.Completed);123 } catch (Exception e) {124 log.error(e.getMessage(), e);125 upload.setUploadStatus(UploadStatus.Failed);126 }127 }128 public List<UploadVersion> setSignedFlag(List<UploadVersion> versions, Long deviceId) {129 ProvisioningProfileDevice profileDevice = profileDeviceService.findByAgentDeviceId(deviceId);130 if (profileDevice != null) {131 for (UploadVersion version : versions) {132 if (version.getUploadType() == UploadType.IPA) {133 ProvisioningProfileUpload profileUpload = profileUploadService.findByDeviceIdAndUploadId(deviceId,134 version.getUploadId()).get();135 version.setSigned((profileUpload != null));136 }137 }138 } else {139 log.info("The device is not provisioned. Unless the device is provisioned and upload file is resigned it can't used");140 }141 return versions;142 }143 public UploadVersion create(String versionName, Long uploadId, MultipartFile uploadedMultipartFile, UploadType type, Upload upload) throws TestsigmaException {144 UploadVersion uploadVersion = new UploadVersion();145 uploadVersion.setUploadId(uploadId);146 uploadVersion.setName(versionName);147 uploadVersion.setUploadType(type);148 uploadVersion.setUpload(upload);149 File uploadedFile = copyUploadToTempFile(uploadedMultipartFile);150 uploadVersion.setFileSize(uploadedMultipartFile.getSize());151 uploadVersion.setFileName(ObjectUtils.defaultIfNull(uploadedMultipartFile.getOriginalFilename(), "tmp")152 .replaceAll("\\s+", "_"));153 uploadVersion = this.uploadVersionRepository.save(uploadVersion);154 uploadFile(uploadedFile, uploadVersion);155 return uploadVersion;156 }157 private File copyUploadToTempFile(MultipartFile uploadedFile) throws TestsigmaException {158 try {159 String fileName = uploadedFile.getOriginalFilename().replaceAll("\\s+", "_");160 String fileBaseName = FilenameUtils.getBaseName(fileName);161 String extension = FilenameUtils.getExtension(fileName);162 if (StringUtils.isNotBlank(extension)) {163 extension = "." + extension;164 }165 File tempFile = File.createTempFile(fileBaseName + "_", extension);166 log.info("Transferring uploaded multipart file to - " + tempFile.getAbsolutePath());167 uploadedFile.transferTo(tempFile.toPath());168 return tempFile;169 } catch (Exception e) {170 log.error(e.getMessage(), e);171 throw new TestsigmaException(e.getMessage(), e);172 }173 }174 public void resignTheUpload(UploadVersion version) {175 if (version.getUploadType() == UploadType.IPA) {176 ReSignTask reSignTask = new ReSignTask(webApplicationContext, null, version);177 ReSignTaskFactory.getInstance().startTask(reSignTask);178 } else {179 log.info(String.format("Upload Type - [%s]. Skipping iOS app resign upload task...", version.getUploadType()));180 }181 }182 public void publishEvent(UploadVersion version, EventType eventType) {183 UploadVersionEvent<UploadVersion> event = createEvent(version, eventType);184 log.info("Publishing event - " + event.toString());185 applicationEventPublisher.publishEvent(event);186 }187 public UploadVersionEvent<UploadVersion> createEvent(UploadVersion version, EventType eventType) {188 UploadVersionEvent<UploadVersion> event = new UploadVersionEvent<>();189 event.setEventData(version);190 event.setEventType(eventType);191 return event;192 }193 public void export(BackupDTO backupDTO) throws IOException, ResourceNotFoundException {194 if (!backupDTO.getIsUploadsEnabled()) return;195 log.debug("backup process for upload initiated");196 writeXML("upload_version", backupDTO, PageRequest.of(0, 25));197 log.debug("backup process for upload completed");198 }199 public Specification<UploadVersion> getExportXmlSpecification(BackupDTO backupDTO) throws ResourceNotFoundException {200 WorkspaceVersion applicationVersion = workspaceVersionService.find(backupDTO.getWorkspaceVersionId());201 List<Long> uploads =202 uploadService.findAllByApplicationId(applicationVersion.getWorkspaceId()).stream().map(upload -> upload.getId()).collect(Collectors.toList());203 SearchCriteria criteria = new SearchCriteria("uploadId", SearchOperation.IN, uploads);204 List<SearchCriteria> params = new ArrayList<>();205 params.add(criteria);206 UploadVersionSpecificationsBuilder uploadSpecificationsBuilder = new UploadVersionSpecificationsBuilder();207 uploadSpecificationsBuilder.params = params;208 return uploadSpecificationsBuilder.build();209 }210 @Override211 public Page<UploadVersion> findAll(Specification<UploadVersion> specification, Pageable pageRequest) {212 return this.uploadVersionRepository.findAll(specification, pageRequest);213 }214 @Override215 protected List<UploadVersionXMLDTO> mapToXMLDTOList(List<UploadVersion> list) {216 return mapper.mapUploads(list, this, null);217 }218 @Override219 protected List<UploadVersionXMLDTO> mapToXMLDTOList(List<UploadVersion> list, BackupDTO backupDTO) {220 return mapper.mapUploads(list, this, backupDTO.getSrcFiles());221 }222 public void delete(UploadVersion version) {223 this.uploadVersionRepository.delete(version);224 }225 public void importXML(BackupDTO importDTO) throws IOException, ResourceNotFoundException {226 if (!importDTO.getIsUploadsEnabled()) return;227 log.debug("import process for upload versions initiated");228 importFiles("upload_version", importDTO);229 log.debug("import process for upload versions completed");230 }231 @Override232 public List<UploadVersion> readEntityListFromXmlData(String xmlData, XmlMapper xmlMapper, BackupDTO importDTO) throws JsonProcessingException, ResourceNotFoundException {233 List<UploadVersionXMLDTO> uploads = xmlMapper.readValue(xmlData, new TypeReference<>() {234 });235 if (!hasToSkip(null, importDTO)) {236 return mapper.mapUploadVersionsList(uploads);237 } else {238 return new ArrayList<>();239 }240 }241 @Override242 public boolean hasToSkip(UploadVersion upload, BackupDTO importDTO) {243 return !importDTO.getIsSameApplicationType();244 }245 @Override246 void updateImportedId(UploadVersion upload, UploadVersion previous, BackupDTO importDTO) {247 previous.setImportedId(upload.getId());248 save(previous);249 }250 @Override251 UploadVersion processAfterSave(Optional<UploadVersion> previous, UploadVersion present, UploadVersion toImport, BackupDTO importDTO) {252 try {253 String originalFileName = ObjectUtils.defaultIfNull(present.getFileName(), "tmp")254 .replaceAll("\\s+", "_");255 String downloadPath = Files.createTempDirectory(present.getFileName()).toFile().getAbsolutePath() + "/" + originalFileName;256 client.downloadRedirectFile(toImport.getDownloadURL(), downloadPath, new HashMap<>());257 this.updateUploadWithLatestUploadVersion(present, present.getUploadId());258 uploadFile(new File(downloadPath), present);259 this.uploadVersionRepository.save(present);260 } catch (IOException | TestsigmaException e) {261 log.error("Failed to upload file", e.getMessage(), e);262 }263 return present;264 }265 @Override266 public Optional<UploadVersion> findImportedEntity(UploadVersion version, BackupDTO importDTO) {267 return uploadVersionRepository.findAllByUploadIdAndImportedId(version.getImportedId(), version.getId());268 }269 @Override270 public UploadVersion processBeforeSave(Optional<UploadVersion> previous, UploadVersion present, UploadVersion toImport, BackupDTO importDTO) throws ResourceNotFoundException {271 present.setImportedId(present.getId());...
updateUploadWithLatestUploadVersion
Using AI Code Generation
1import com.testsigma.service.UploadVersionService;2import com.testsigma.service.UploadVersionServiceFactory;3import com.testsigma.service.UploadVersionServiceFactoryImpl;4import com.testsigma.service.UploadVersionServiceParams;5UploadVersionServiceFactory factory = new UploadVersionServiceFactoryImpl();6UploadVersionService uploadVersionService = factory.createUploadVersionService();7UploadVersionServiceParams params = new UploadVersionServiceParams();8params.setUploadId(1L);9params.setVersionId(1L);10params.setUploadVersionId(1L);11uploadVersionService.updateUploadWithLatestUploadVersion(params);12import com.testsigma.service.UploadVersionService13import com.testsigma.service.UploadVersionServiceFactory14import com.testsigma.service.UploadVersionServiceFactoryImpl15import com.testsigma.service.UploadVersionServiceParams16UploadVersionServiceFactory factory = new UploadVersionServiceFactoryImpl()17UploadVersionService uploadVersionService = factory.createUploadVersionService()18UploadVersionServiceParams params = new UploadVersionServiceParams()19params.setUploadId(1L)20params.setVersionId(1L)21params.setUploadVersionId(1L)22uploadVersionService.updateUploadWithLatestUploadVersion(params)23import com.testsigma.service.UploadVersionService;24import com.testsigma.service.UploadVersionServiceFactory;25import com.testsigma.service.UploadVersionServiceFactoryImpl;26import com.testsigma.service.UploadVersionServiceParams;27UploadVersionServiceFactory factory = new UploadVersionServiceFactoryImpl();28UploadVersionService uploadVersionService = factory.createUploadVersionService();29UploadVersionServiceParams params = new UploadVersionServiceParams();30params.setUploadId(1L);31params.setVersionId(1L);32params.setUploadVersionId(1L);33uploadVersionService.updateUploadWithLatestUploadVersion(params);34import com
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!!