How to use export method of com.testsigma.service.AgentService class

Best Testsigma code snippet using com.testsigma.service.AgentService.export

Source:AgentService.java Github

copy

Full Screen

...7package com.testsigma.service;8import com.fasterxml.jackson.core.type.TypeReference;9import com.testsigma.config.ApplicationConfig;10import com.testsigma.dto.BackupDTO;11import com.testsigma.dto.export.AgentXMLDTO;12import com.testsigma.event.AgentEvent;13import com.testsigma.event.EventType;14import com.testsigma.exception.ResourceNotFoundException;15import com.testsigma.exception.TestsigmaException;16import com.testsigma.mapper.AgentMapper;17import com.testsigma.model.Agent;18import com.testsigma.model.AgentDevice;19import com.testsigma.model.TestDevice;20import com.testsigma.model.TestPlan;21import com.testsigma.repository.AgentRepository;22import com.testsigma.specification.AgentSpecificationsBuilder;23import com.testsigma.specification.SearchCriteria;24import com.testsigma.specification.SearchOperation;25import com.testsigma.specification.TestDeviceSpecificationsBuilder;26import com.testsigma.util.HttpClient;27import com.testsigma.web.request.AgentRequest;28import lombok.NonNull;29import lombok.RequiredArgsConstructor;30import lombok.extern.log4j.Log4j2;31import org.apache.http.Header;32import org.apache.http.HttpHeaders;33import org.apache.http.message.BasicHeader;34import org.json.JSONObject;35import org.springframework.beans.factory.annotation.Autowired;36import org.springframework.context.ApplicationEventPublisher;37import org.springframework.context.annotation.Lazy;38import org.springframework.data.domain.Page;39import org.springframework.data.domain.PageRequest;40import org.springframework.data.domain.Pageable;41import org.springframework.data.jpa.domain.Specification;42import org.springframework.stereotype.Service;43import java.io.IOException;44import java.sql.Timestamp;45import java.util.ArrayList;46import java.util.Date;47import java.util.List;48import java.util.UUID;49import java.util.stream.Collectors;50@Log4j251@Service52@RequiredArgsConstructor(onConstructor = @__({@Autowired, @Lazy}))53public class AgentService extends XMLExportService<Agent> {54 private final AgentRepository agentRepository;55 private final AgentMapper mapper;56 private final ApplicationEventPublisher applicationEventPublisher;57 private final AgentDeviceService agentDeviceService;58 private final TestPlanService testPlanService;59 private final TestDeviceService testDeviceService;60 private final AgentMapper exportAgentMapper;61 private final HttpClient httpClient;62 private final ApplicationConfig applicationConfig;63 private final JWTTokenService jwtTokenService;64 public Agent find(Long id) throws ResourceNotFoundException {65 return agentRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Agent is not found with id:" + id));66 }67 public Agent create(@NonNull Agent agent) {68 agent.setUpdatedDate(new Timestamp(new Date().getTime()));69 agent.setCreatedDate(new Timestamp(new Date().getTime()));70 agent.setUniqueId(UUID.randomUUID().toString());71 agent = agentRepository.save(agent);72 return agent;73 }74 public Agent create(@NonNull AgentRequest agentRequest) throws TestsigmaException {75 Agent agent = mapper.map(agentRequest);76 agent = create(agent);77 return agent;78 }79 public void createLocalAgent(Agent agent) throws TestsigmaException {80 agent = create(agent);81 String url = applicationConfig.getLocalAgentUrl() +"/api/v1/" + agent.getUniqueId() + "/register?jwtApiKey="82 + agent.generateJwtApiKey(jwtTokenService.getServerUuid());83 httpClient.put(url, getHeaders(), new JSONObject(), new TypeReference<>() {84 });85 }86 public Page<Agent> findAll(Specification<Agent> specification, Pageable pageable) {87 return agentRepository.findAll(specification, pageable);88 }89 public void destroy(@NonNull Agent agent) {90 List<AgentDevice> agentDevices = agentDeviceService.findAllByAgent(agent.getId());91 agentDevices.forEach(agentDevice -> agentDeviceService.publishEvent(agentDevice, EventType.DELETE));92 agentRepository.delete(agent);93 publishEvent(agent, EventType.DELETE);94 }95 public boolean isAgentActive(Long agentId) throws ResourceNotFoundException {96 Agent agent = find(agentId);97 long lastUpdatedTime = agent.getUpdatedDate().getTime();98 long currentTime = java.lang.System.currentTimeMillis();99 return currentTime - lastUpdatedTime <= 10 * 60 * 1000;100 }101 public Agent findByUniqueId(@NonNull String uniqueId) throws ResourceNotFoundException {102 Agent agent = null;103 try {104 agent = agentRepository.findByUniqueId(uniqueId);105 } catch (Exception e) {106 log.error(e.getMessage(), e);107 }108 if (agent == null) {109 throw new ResourceNotFoundException("Agent is not found");110 }111 return agent;112 }113 public Agent update(@NonNull AgentRequest agentRequest, String uniqueId) throws ResourceNotFoundException {114 boolean isRegistered = false;115 Agent db = findByUniqueId(uniqueId);116 if (db.getOsType() != null) {117 isRegistered = true;118 }119 mapper.map(agentRequest, db);120 db.setUpdatedDate(new Timestamp(java.lang.System.currentTimeMillis()));121 db = agentRepository.save(db);122 if (!isRegistered && db.getOsType() != null) {123 publishEvent(db, EventType.CREATE);124 }125 return db;126 }127 public void publishEvent(Agent agent, EventType eventType) {128 AgentEvent<Agent> event = createEvent(agent, eventType);129 log.info("Publishing event - " + event.toString());130 applicationEventPublisher.publishEvent(event);131 }132 public AgentEvent<Agent> createEvent(Agent agent, EventType eventType) {133 AgentEvent<Agent> event = new AgentEvent<>();134 event.setEventData(agent);135 event.setEventType(eventType);136 return event;137 }138 public void export(BackupDTO backupDTO) throws IOException, ResourceNotFoundException {139 if (!backupDTO.getIsAgentEnabled()) return;140 log.debug("backup process for agent initiated");141 writeXML("agent", backupDTO, PageRequest.of(0, 25));142 log.debug("backup process for agent completed");143 }144 @Override145 protected List<AgentXMLDTO> mapToXMLDTOList(List<Agent> list) {146 return exportAgentMapper.mapAgents(list);147 }148 @Override149 public Specification<Agent> getExportXmlSpecification(BackupDTO backupDTO) throws ResourceNotFoundException {150 List<TestPlan> testPlanList = testPlanService.findAllByWorkspaceVersionId(backupDTO.getWorkspaceVersionId());151 List<Long> testPlanIds = testPlanList.stream().map(testPlan -> testPlan.getId()).collect(Collectors.toList());152 SearchCriteria criteria = new SearchCriteria("testPlanId", SearchOperation.IN, testPlanIds);153 List<SearchCriteria> params = new ArrayList<>();154 params.add(criteria);155 TestDeviceSpecificationsBuilder testDeviceSpecificationsBuilder = new TestDeviceSpecificationsBuilder();156 testDeviceSpecificationsBuilder.params = params;157 Page<TestDevice> page = testDeviceService.findAll(testDeviceSpecificationsBuilder.build(), PageRequest.of(0, 100));158 List<Long> agentIds = page.getContent().stream().map(testDevice -> {159 if (testDevice.getAgent() != null) {160 return testDevice.getAgent().getId();...

Full Screen

Full Screen

Source:BackupDetailService.java Github

copy

Full Screen

...8import com.testsigma.config.StorageServiceFactory;9import com.testsigma.model.StorageAccessLevel;10import com.testsigma.constants.MessageConstants;11import com.testsigma.dto.BackupDTO;12import com.testsigma.dto.export.BaseXMLDTO;13import com.testsigma.exception.ResourceNotFoundException;14import com.testsigma.exception.TestsigmaException;15import com.testsigma.mapper.BackupDetailMapper;16import com.testsigma.model.BackupDetail;17import com.testsigma.model.BackupStatus;18import com.testsigma.repository.BackupDetailRepository;19import com.testsigma.web.request.BackupRequest;20import lombok.RequiredArgsConstructor;21import lombok.extern.log4j.Log4j2;22import org.springframework.beans.factory.annotation.Autowired;23import org.springframework.data.domain.Page;24import org.springframework.data.domain.Pageable;25import org.springframework.data.jpa.domain.Specification;26import org.springframework.stereotype.Service;27import java.io.IOException;28import java.net.URL;29import java.sql.Timestamp;30import java.util.List;31import java.util.Optional;32@Log4j233@Service34@RequiredArgsConstructor(onConstructor = @__({@Autowired}))35public class BackupDetailService extends XMLExportService<BackupDetail> {36 private final BackupDetailRepository repository;37 private final StorageServiceFactory storageServiceFactory;38 private final AgentService agentService;39 private final WorkspaceService workspaceService;40 private final AttachmentService attachmentService;41 private final TestDeviceService testDeviceService;42 private final TestPlanService testPlanService;43 private final RestStepService reststepService;44 private final TestCaseService testcaseService;45 private final TestCasePriorityService testCasePriorityService;46 private final TestCaseTypeService testCaseTypeService;47 private final TestDataProfileService testDataProfileService;48 private final TestStepService teststepService;49 private final ElementService elementService;50 private final WorkspaceVersionService versionService;51 private final ElementScreenService elementScreenService;52 private final UploadService uploadService;53 private final UploadVersionService uploadVersionService;54 private final BackupDetailMapper exportBackupEntityMapper;55 public BackupDetail find(Long id) throws ResourceNotFoundException {56 return repository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Backup is not found with id:" + id));57 }58 public Page<BackupDetail> findAll(Pageable pageable) {59 return repository.findAll(pageable);60 }61 public Optional<URL> downLoadURL(BackupDetail backupDetail) {62 return storageServiceFactory.getStorageService().generatePreSignedURLIfExists(63 "/backup/" + backupDetail.getName(), StorageAccessLevel.READ, 300);64 }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 }...

Full Screen

Full Screen

export

Using AI Code Generation

copy

Full Screen

1import com.testsigma.service.AgentService;2import com.testsigma.service.AgentServiceService;3import com.testsigma.service.AgentServiceServiceLocator;4import java.io.File;5import java.io.FileInputStream;6import java.io.InputStream;7import javax.activation.DataHandler;8import javax.activation.DataSource;9import javax.activation.FileDataSource;10import javax.xml.rpc.ServiceException;11import org.apache.axis.attachments.AttachmentPart;12public class 2 {13public static void main(String[] args) throws Exception {14AgentServiceService service = new AgentServiceServiceLocator();15AgentService port = service.getAgentService();16File file = new File("C:/Users/Downloads/2.pdf");17DataSource source = new FileDataSource(file);18DataHandler handler = new DataHandler(source);19AttachmentPart attachment = new AttachmentPart(handler);20attachment.setContentId("file");21attachment.setContentType("application/pdf");22attachment.setDisposition("attachment");23attachment.setMimeHeader("Content-Transfer-Encoding", "binary");24attachment.setMimeHeader("Content-Disposition", "attachment; filename=\"2.pdf\"");25InputStream is = new FileInputStream(file);26attachment.setRawContent(is, "application/pdf");27attachment.setMimeHeader("Content-Length", String.valueOf(file.length()));28AttachmentPart[] attachments = new AttachmentPart[1];29attachments[0] = attachment;30String result = port.export("2", "2", "2", "2", "2", "2", "2", "2", attachments);31System.out.println(result);32}33}34[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:java (default-cli) on project test: An exception occured while executing the Java class. null: InvocationTargetException: Invalid MIME header: Content-Transfer-Encoding: binary -> [Help 1]

Full Screen

Full Screen

export

Using AI Code Generation

copy

Full Screen

1import com.testsigma.service.AgentService;2public class 2 {3 public static void main(String[] args) {4 AgentService agentService = new AgentService();5 agentService.export("C:\\Users\\abc\\Desktop\\test");6 }7}8import com.testsigma.service.AgentService;9public class 3 {10 public static void main(String[] args) {11 AgentService agentService = new AgentService();12 agentService.export("C:\\Users\\abc\\Desktop\\test");13 }14}15import com.testsigma.service.AgentService;16public class 4 {17 public static void main(String[] args) {18 AgentService agentService = new AgentService();19 agentService.export("C:\\Users\\abc\\Desktop\\test");20 }21}22import com.testsigma.service.AgentService;23public class 5 {24 public static void main(String[] args) {25 AgentService agentService = new AgentService();26 agentService.export("C:\\Users\\abc\\Desktop\\test");27 }28}29import com.testsigma.service.AgentService;30public class 6 {31 public static void main(String[] args) {32 AgentService agentService = new AgentService();33 agentService.export("C:\\Users\\abc\\Desktop\\test");34 }35}36import com.testsigma.service.AgentService;37public class 7 {38 public static void main(String[] args) {39 AgentService agentService = new AgentService();40 agentService.export("C:\\Users\\abc\\Desktop\\test");41 }42}43import com.testsigma.service.AgentService;44public class 8 {45 public static void main(String[] args) {46 AgentService agentService = new AgentService();47 agentService.export("C:\\Users\\abc\\Desktop\\test");48 }49}

Full Screen

Full Screen

export

Using AI Code Generation

copy

Full Screen

1package com.testsigma.test;2import com.testsigma.service.AgentService;3import com.testsigma.service.AgentServiceException;4import com.testsigma.service.AgentServiceFactory;5import com.testsigma.service.TestResult;6import com.testsigma.service.TestRu

Full Screen

Full Screen

export

Using AI Code Generation

copy

Full Screen

1import com.testsigma.service.AgentService;2import com.testsigma.service.TestSigmaAgent;3import com.testsigma.service.TestSigmaAgentFactory;4public class 2 {5 public static void main(String[] args) throws Exception {6 TestSigmaAgent agent = TestSigmaAgentFactory.getInstance();7 AgentService.export(agent);8 AgentService.closeConnection();9 }10}11import com.testsigma.service.AgentService;12import com.testsigma.service.TestSigmaAgent;13import com.testsigma.service.TestSigmaAgentFactory;14public class 3 {15 public static void main(String[] args) throws Exception {16 TestSigmaAgent agent = TestSigmaAgentFactory.getInstance();17 AgentService.export(agent);18 AgentService.closeConnection();19 }20}21import com.testsigma.service.AgentService;22import com.testsigma.service.TestSigmaAgent;23import com.testsigma.service.TestSigmaAgentFactory;24public class 4 {25 public static void main(String[] args) throws Exception {26 TestSigmaAgent agent = TestSigmaAgentFactory.getInstance();27 AgentService.export(agent);28 AgentService.closeConnection();29 }30}31import com.testsigma.service.AgentService;32import com.testsigma.service.TestSigmaAgent;33import com.testsigma.service.TestSigmaAgentFactory;34public class 5 {35 public static void main(String[] args) throws Exception {36 TestSigmaAgent agent = TestSigmaAgentFactory.getInstance();

Full Screen

Full Screen

export

Using AI Code Generation

copy

Full Screen

1package com.testsigma.service;2import java.io.File;3import java.io.FileInputStream;4import java.io.FileOutputStream;5import java.io.IOException;6import java.io.InputStream;7import java.io.OutputStream;8import java.util.zip.ZipEntry;9import java.util.zip.ZipOutputStream;10public class AgentService {11public static void export(String filePath) throws IOException {12File zipFile = new File(filePath);13byte[] buffer = new byte[1024];14if(zipFile.exists()) {15zipFile.delete();16}17ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipFile

Full Screen

Full Screen

export

Using AI Code Generation

copy

Full Screen

1package com.testsigma.test;2import java.io.File;3import java.io.IOException;4import java.net.MalformedURLException;5import java.net.URL;6import java.util.HashMap;7import java.util.Map;8import org.openqa.selenium.By;9import org.openqa.selenium.WebDriver;10import org.openqa.selenium.WebElement;11import org.openqa.selenium.chrome.ChromeDriver;12import org.openqa.selenium.remote.DesiredCapabilities;13import org.openqa.selenium.remote.RemoteWebDriver;14import org.testng.annotations.AfterMethod;15import org.testng.annotations.BeforeMethod;16import org.testng.annotations.Test;17import com.testsigma.service.AgentService;18public class TestClass {19 WebDriver driver;20 String driverPath = "C:/Users/Downloads/chromedriver_win32/chromedriver.exe";21 String testId = "testId";22 String testSuiteId = "testSuiteId";23 String testCaseId = "testCaseId";24 String testRunId = "testRunId";25 String testPlanId = "testPlanId";26 String testProjectId = "testProjectId";27 String testEnvironmentId = "testEnvironmentId";28 String testBuildId = "testBuildId";29 String testVersionId = "testVersionId";30 String testReleaseId = "testReleaseId";31 String testCycleId = "testCycleId";32 String testSuiteRunId = "testSuiteRunId";33 String testSuiteCycleId = "testSuiteCycleId";34 String testSuitePlanId = "testSuitePlanId";35 String testSuiteProjectId = "testSuiteProjectId";36 String testSuiteVersionId = "testSuiteVersionId";37 String testSuiteReleaseId = "testSuiteReleaseId";38 String testSuiteEnvironmentId = "testSuiteEnvironmentId";39 String testSuiteBuildId = "testSuiteBuildId";40 String testSuiteCycleRunId = "testSuiteCycleRunId";41 String testSuitePlanRunId = "testSuitePlanRunId";42 String testSuiteProjectRunId = "testSuiteProjectRunId";43 String testSuiteVersionRunId = "testSuiteVersionRunId";44 String testSuiteReleaseRunId = "testSuiteReleaseRunId";45 String testSuiteEnvironmentRunId = "testSuiteEnvironmentRunId";46 String testSuiteBuildRunId = "testSuiteBuildRunId";

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