How to use save method of com.testsigma.service.UploadService class

Best Testsigma code snippet using com.testsigma.service.UploadService.save

Source:UploadVersionService.java Github

copy

Full Screen

...80 public List<UploadVersion> findValidUploadsByUploadTypesIn(Collection<UploadType> uploadType) {81 return this.uploadVersionRepository.findAllByUploadTypeIn(uploadType);82 }83 public UploadVersion update(UploadVersion uploadVersion) {84 return this.uploadVersionRepository.save(uploadVersion);85 }86 public String getPreSignedURL(UploadVersion uploadVersion) {87 URL newPreSignedURL =88 storageServiceFactory.getStorageService().generatePreSignedURL(89 uploadVersion.getPath(),90 StorageAccessLevel.READ, 300);91 return newPreSignedURL.toString();92 }93 public void uploadFile(File uploadedFile, UploadVersion uploadVersion) throws TestsigmaException {94 try {95 String storageFilePath = uploadVersion.getS3Path();96 uploadToStorage(storageFilePath, uploadedFile, uploadVersion);97 UploadVersionAppInfo uploadedVersion = appParserService.parseFile(uploadedFile);98 uploadVersion.setPath(storageFilePath);99 uploadVersion.setActivity(uploadedVersion.getAppActivity());100 uploadVersion.setPackageName(uploadedVersion.getPackageName());101 uploadVersion.setVersionName(uploadedVersion.getAppVersion());102 uploadVersion.setBundleId(uploadedVersion.getBundleId());103 this.uploadVersionRepository.save(uploadVersion);104 resignTheUpload(uploadVersion);105 publishEvent(uploadVersion, EventType.UPDATE);106 } catch (Exception e) {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());272 if (previous.isPresent() && importDTO.isHasToReset()) {273 present.setId(previous.get().getId());274 } else {275 present.setId(null);276 }277 Optional<Upload> importedUpload = uploadService.findByImportedIdAndWorkspaceId(present.getUploadId(),importDTO.getWorkspaceId());278 present.setUploadId(importedUpload.get().getId());279 present.setUpload(importedUpload.get());280 return present;281 }282 @Override283 public UploadVersion copyTo(UploadVersion version) {284 return mapper.copyVersion(version);285 }286 @Override287 public UploadVersion save(UploadVersion version) {288 return uploadVersionRepository.save(version);289 }290 @Override291 public Optional<UploadVersion> getRecentImportedEntity(BackupDTO importDTO, Long... ids) {292 // NEED TO CHECK WITH CHANDRA ONCE HOW BEST WE CAN HANDLE THIS293// Long importedId = ids[0];294// return uploadVersionRepository.findAllByApplicationIdAndImportedId(importDTO.getApplicationId(), importedId);295 return Optional.empty();296 }297 @Override298 public Optional<UploadVersion> findImportedEntityHavingSameName(Optional<UploadVersion> previous, UploadVersion current, BackupDTO importDTO) throws ResourceNotFoundException {299 Optional<Upload> upload= uploadService.findByImportedIdAndWorkspaceId(current.getUploadId(), importDTO.getWorkspaceId());300 if (upload.isPresent())301 return uploadVersionRepository.findByNameAndUploadId(current.getName(), upload.get().getId());302 else return Optional.empty();...

Full Screen

Full Screen

Source:BackupDetailService.java Github

copy

Full Screen

...65 public BackupDetail create(BackupDetail backupDetail) {66 backupDetail.setMessage(MessageConstants.BACKUP_IS_IN_PROGRESS);67 backupDetail.setStatus(BackupStatus.IN_PROGRESS);68 backupDetail.setCreatedDate(new Timestamp(System.currentTimeMillis()));69 backupDetail = this.repository.save(backupDetail);70 return backupDetail;71 }72 public BackupDetail save(BackupDetail backupDetail) {73 return this.repository.save(backupDetail);74 }75 public void destroy(Long id) throws ResourceNotFoundException {76 BackupDetail detail = this.find(id);77 this.repository.delete(detail);78 }79 @Override80 protected Page<BackupDetail> findAll(Specification<BackupDetail> specification, Pageable pageRequest) throws ResourceNotFoundException {81 return null;82 }83 @Override84 protected List<? extends BaseXMLDTO> mapToXMLDTOList(List<BackupDetail> list) {85 return null;86 }87 @Override88 public Specification<BackupDetail> getExportXmlSpecification(BackupDTO backupDTO) throws ResourceNotFoundException {89 return null;90 }91 public void export(BackupRequest request) throws IOException, TestsigmaException {92 BackupDTO backupDTORequest = exportBackupEntityMapper.map(request);93 BackupDetail backupDetailRequest = exportBackupEntityMapper.map(backupDTORequest);94 final BackupDetail backupDetail = create(backupDetailRequest);95 final BackupDTO backupDTO = exportBackupEntityMapper.mapTo(backupDetail);96 log.debug("initiating backup - " + backupDetail.getId());97 new Thread(() -> {98 try {99 log.debug("backup process started for ::" + backupDetail.getId());100 initExportFolder(backupDTO);101 workspaceService.export(backupDTO);102 versionService.export(backupDTO);103 testCasePriorityService.export(backupDTO);104 testCaseTypeService.export(backupDTO);105 elementScreenService.export(backupDTO);106 elementService.export(backupDTO);107 testDataProfileService.export(backupDTO);108 attachmentService.export(backupDTO);109 agentService.export(backupDTO);110 uploadService.export(backupDTO);111 uploadVersionService.export(backupDTO);112 testcaseService.export(backupDTO);113 teststepService.export(backupDTO);114 reststepService.export(backupDTO);115 testPlanService.export(backupDTO);116 testDeviceService.export(backupDTO);117 backupDetail.setSrcFiles(backupDTO.getSrcFiles());118 backupDetail.setDestFiles(backupDTO.getDestFiles());119 exportToStorage(backupDetail);120 log.debug("backup process export completed");121 } catch (Exception e) {122 log.error(e.getMessage(), e);123 backupDetail.setStatus(BackupStatus.FAILURE);124 backupDetail.setMessage(e.getMessage());125 repository.save(backupDetail);126 destroy(backupDTO);127 } catch (Error error) {128 log.error(error.getMessage(), error);129 } finally {130 destroy(backupDTO);131 log.debug("backup process for completed");132 }133 }).start();134 }135}...

Full Screen

Full Screen

save

Using AI Code Generation

copy

Full Screen

1package com.testsigma.service;2import java.io.File;3import java.io.FileInputStream;4import java.io.FileNotFoundException;5import java.io.IOException;6import java.io.InputStream;7import java.net.MalformedURLException;8import java.net.URL;9import java.net.URLConnection;10import java.util.HashMap;11import java.util.Map;12import com.testsigma.util.FileUtil;13public class UploadService {14private static final String UPLOAD_FILE_NAME = "file";15private static final String UPLOAD_FILE_TYPE = "fileType";16private static final String UPLOAD_FILE_SIZE = "fileSize";17private static final String UPLOAD_FILE_DESCRIPTION = "description";18private static final String UPLOAD_FILE_TAGS = "tags";19private static final String UPLOAD_FILE_NAME_ON_SERVER = "fileNameOnServer";20private static final String UPLOAD_FILE_SERVER_LOCATION = "serverLocation";21private static final String UPLOAD_FILE_SERVER_NAME = "serverName";22private static final String UPLOAD_FILE_SERVER_PORT = "serverPort";23private static final String UPLOAD_FILE_SERVER_PROTOCOL = "serverProtocol";24private static final String UPLOAD_FILE_SERVER_URL = "serverUrl";25private static final String UPLOAD_FILE_SERVER_FILE_URL = "serverFileUrl";26private static final String UPLOAD_FILE_SERVER_FILE_PATH = "serverFilePath";27private static final String UPLOAD_FILE_SERVER_FILE_NAME = "serverFileName";28private static final String UPLOAD_FILE_SERVER_FILE_EXTENSION = "serverFileExtension";29private static final String UPLOAD_FILE_SERVER_FILE_SIZE = "serverFileSize";30private static final String UPLOAD_FILE_SERVER_FILE_TYPE = "serverFileType";31private static final String UPLOAD_FILE_SERVER_FILE_DESCRIPTION = "serverFileDescription";32private static final String UPLOAD_FILE_SERVER_FILE_TAGS = "serverFileTags";33private static final String UPLOAD_FILE_SERVER_FILE_NAME_ON_SERVER = "serverFileNameOnServer";34private static final String UPLOAD_FILE_SERVER_FILE_CREATED_TIME = "serverFileCreatedTime";35private static final String UPLOAD_FILE_SERVER_FILE_MODIFIED_TIME = "serverFileModifiedTime";36private static final String UPLOAD_FILE_SERVER_FILE_ACCESSED_TIME = "serverFileAccessedTime";37private static final String UPLOAD_FILE_SERVER_FILE_IS_DIRECTORY = "serverFileIsDirectory";38private static final String UPLOAD_FILE_SERVER_FILE_IS_FILE = "serverFileIsFile";39private static final String UPLOAD_FILE_SERVER_FILE_IS_HIDDEN = "serverFileIsHidden";40private static final String UPLOAD_FILE_SERVER_FILE_IS_READABLE = "serverFileIsReadable";

Full Screen

Full Screen

save

Using AI Code Generation

copy

Full Screen

1package com.testsigma.service;2import java.io.File;3import java.io.FileInputStream;4import java.io.FileNotFoundException;5import java.io.IOException;6import java.io.InputStream;7import java.io.OutputStream;8import java.net.HttpURLConnection;9import java.net.URL;10import java.util.List;11import java.util.Map;12public class UploadService {13 private final String boundary;14";15 HttpURLConnection httpConn;16 String charset;17 OutputStream outputStream;18 InputStream inputStream;19 public UploadService(String requestURL, String charset) throws IOException {20 this.charset = charset;21 boundary = "===" + System.currentTimeMillis() + "===";22 URL url = new URL(requestURL);23 httpConn = (HttpURLConnection) url.openConnection();24 httpConn.setUseCaches(false);25 httpConn.setDoInput(true);26 httpConn.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);27 httpConn.setRequestProperty("User-Agent", "CodeJava Agent");28 httpConn.setRequestProperty("Test", "Bonjour");29 outputStream = httpConn.getOutputStream();30 inputStream = httpConn.getInputStream();31 }32 public void addFormField(String name, String value) throws IOException {33 outputStream.write(("--" + boundary + LINE_FEED).getBytes());34 outputStream.write(("Content-Disposition: form-data; name=\"" + name + "\"").getBytes());35 outputStream.write(LINE_FEED.getBytes());36 outputStream.write(LINE_FEED.getBytes());37 outputStream.write(value.getBytes());38 outputStream.write(LINE_FEED.getBytes());39 }40 public void addFilePart(String fieldName, File uploadFile) throws IOException {41 String fileName = uploadFile.getName();42 outputStream.write(("--" + boundary + LINE_FEED).getBytes());43 outputStream.write(("Content-Disposition: form-data; name=\"" + fieldName + "\"; filename=\"" + fileName + "\"").getBytes());44 outputStream.write(LINE_FEED.getBytes());45 outputStream.write(("Content-Type: " + URLConnection.guessContentTypeFromName(fileName)).getBytes());46 outputStream.write(LINE_FEED.getBytes());47 outputStream.write(("Content-Transfer-Encoding: binary").getBytes());48 outputStream.write(LINE_FEED.getBytes());49 outputStream.write(LINE_FEED.getBytes());50 FileInputStream inputStream = new FileInputStream(uploadFile);51 byte[] buffer = new byte[4096];52 int bytesRead = -1;53 while ((bytesRead = inputStream.read(buffer)) != -1)

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful