-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from Pardus-LiderAhenk/development
Development
- Loading branch information
Showing
83 changed files
with
5,872 additions
and
1,799 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package tr.org.lider; | ||
|
||
import java.time.LocalDate; | ||
import java.time.ZoneId; | ||
import java.time.temporal.ChronoUnit; | ||
import java.util.Date; | ||
import java.util.List; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.scheduling.annotation.EnableScheduling; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Component; | ||
|
||
import tr.org.lider.entities.AgentImpl; | ||
import tr.org.lider.entities.AgentStatus; | ||
import tr.org.lider.message.service.IMessagingService; | ||
import tr.org.lider.repositories.AgentRepository; | ||
import tr.org.lider.services.ConfigurationService; | ||
import tr.org.lider.services.TaskSchedulerService; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Ebru Arslan</a> | ||
*/ | ||
|
||
@Component | ||
@EnableScheduling | ||
public class LiderCronJob { | ||
|
||
@Autowired | ||
private AgentRepository agentRepository; | ||
|
||
@Autowired | ||
private IMessagingService messagingService; | ||
|
||
@Autowired | ||
private ConfigurationService configurationService; | ||
|
||
@Autowired | ||
private TaskSchedulerService taskScheduledService; | ||
|
||
Logger logger = LoggerFactory.getLogger(this.getClass()); | ||
|
||
|
||
@Scheduled(cron = "0 55 10 * * ?") | ||
public void dailyCronJob() { | ||
|
||
|
||
if(configurationService.getMachineEventStatus() == true) { | ||
Date today = new Date(); | ||
List<AgentImpl> agentsEventDate = agentRepository.findAll(); | ||
|
||
for(AgentImpl agent : agentsEventDate) { | ||
|
||
if(!(messagingService.isRecipientOnline(agent.getJid()))) { | ||
|
||
Date eventDate = agent.getEventDate(); | ||
if (eventDate != null) { | ||
LocalDate todayLocalDate = today.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); | ||
LocalDate dbEventDate = eventDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); | ||
|
||
long daysDifference = ChronoUnit.DAYS.between(todayLocalDate, dbEventDate); | ||
|
||
if (daysDifference > -configurationService.getMachineEventDay()) { | ||
|
||
agent.setAgentStatus(AgentStatus.Active); | ||
agentRepository.save(agent); | ||
} | ||
else { | ||
agent.setAgentStatus(AgentStatus.Passive); | ||
agentRepository.save(agent); | ||
} | ||
} | ||
else { | ||
logger.info("Event date is null for agent: " + agent.getId()); | ||
} | ||
} | ||
} | ||
|
||
logger.info("Executed cron job for machine update"); | ||
} | ||
} | ||
|
||
@Scheduled(cron = "0 */20 * * * ?") | ||
public void taskJob() { | ||
try { | ||
taskScheduledService.sendScheduledTaskMesasage(); | ||
} catch (IndexOutOfBoundsException e) { | ||
logger.info("Array size is not enough" + e.getMessage()); | ||
} catch (Throwable t) { | ||
logger.info(t.getMessage()); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
src/main/java/tr/org/lider/controllers/AgentSessionReportController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
package tr.org.lider.controllers; | ||
|
||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
import java.util.HashMap; | ||
|
||
import org.slf4j.Logger; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.access.annotation.Secured; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import tr.org.lider.dto.AgentDTO; | ||
import tr.org.lider.dto.AgentSessionDTO; | ||
import tr.org.lider.entities.AgentImpl; | ||
import tr.org.lider.services.AgentSessionReportService; | ||
import tr.org.lider.services.ExcelExportService; | ||
import tr.org.lider.services.UserSessionReportService; | ||
import tr.org.lider.utils.IUserSessionReport; | ||
|
||
@Secured({"ROLE_ADMIN", "ROLE_USER_SESSION_REPORT" }) | ||
@RestController | ||
@RequestMapping("/api/lider/agent-session") | ||
@Tag(name = "Agent session service", description = "Agent Sesion Report controller") | ||
public class AgentSessionReportController { | ||
|
||
private final Logger logger = org.slf4j.LoggerFactory.getLogger(this.getClass()); | ||
|
||
@Autowired | ||
private AgentSessionReportService agentSessionReportService; | ||
|
||
@Autowired | ||
private UserSessionReportService userSessionReportService; | ||
|
||
@Autowired | ||
private ExcelExportService excelService; | ||
|
||
@Operation(summary = "Find all agents", description = "", tags = { "agent-service" }) | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "200", description = "Find all agents", | ||
content = { @Content(schema = @Schema(implementation = AgentImpl.class)) | ||
}), | ||
@ApiResponse(responseCode = "417", description = "Could not retrieve agents list. Unexpected error occured.", | ||
content = { @Content(schema = @Schema(implementation = String.class)) | ||
}) | ||
}) | ||
@PostMapping(value = "/list", produces = MediaType.APPLICATION_JSON_VALUE) | ||
public ResponseEntity<HashMap<String, Object>> findAllAgents( AgentDTO agentDTO) { | ||
HashMap<String, Object> resultMap = new HashMap<>(); | ||
if(agentDTO.getGetFilterData().isPresent() && agentDTO.getGetFilterData().get()) { | ||
resultMap.put("brands", agentSessionReportService.getBrands()); | ||
resultMap.put("models", agentSessionReportService.getmodels()); | ||
resultMap.put("processors", agentSessionReportService.getProcessors()); | ||
resultMap.put("osVersions", agentSessionReportService.getOSVersions()); | ||
resultMap.put("agentVersions", agentSessionReportService.getAgentVersions()); | ||
resultMap.put("diskType", agentSessionReportService.getDiskType()); | ||
} | ||
Page<AgentImpl> listOfAgents = agentSessionReportService.findAllAgents(agentDTO); | ||
|
||
resultMap.put("agents", listOfAgents); | ||
return ResponseEntity | ||
.status(HttpStatus.OK) | ||
.body(resultMap); | ||
} | ||
|
||
@Operation(summary = "Find agent session detail by id.", description = "", tags = { "agent-service" }) | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "200", description = "Find agent detail by id.", | ||
content = { @Content(schema = @Schema(implementation = AgentImpl.class)) }), | ||
@ApiResponse(responseCode = "404", description = "Agent id not found.Not found.", | ||
content = @Content(schema = @Schema(implementation = String.class))) }) | ||
@PostMapping(value = "/detail", produces = MediaType.APPLICATION_JSON_VALUE) | ||
public ResponseEntity<?> getAgentSessionsDetail(AgentSessionDTO agentSessionDTO) { | ||
logger.debug("Agent id: {} ", agentSessionDTO.getAgentID()); | ||
Page<IUserSessionReport> agentSessionList = agentSessionReportService.getSessionList(agentSessionDTO); | ||
|
||
return ResponseEntity | ||
.status(HttpStatus.OK) | ||
.body(agentSessionList); | ||
} | ||
|
||
@Operation(summary = "Exports filtered agent session list to excel", description = "", tags = { "agent-service" }) | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "200", description = "Created excel file successfully", | ||
content = { @Content(schema = @Schema(implementation = AgentImpl.class)) }), | ||
@ApiResponse(responseCode = "400", description = "Could not create client report.", | ||
content = @Content(schema = @Schema(implementation = String.class))) }) | ||
@PostMapping(value = "/export", produces = MediaType.APPLICATION_JSON_VALUE) | ||
public ResponseEntity<?> export(AgentSessionDTO agentSessionDTO){ | ||
agentSessionDTO.setPageNumber(1); | ||
agentSessionDTO.setPageSize(userSessionReportService.count().intValue()); | ||
Page<IUserSessionReport> agentSessionList = agentSessionReportService.getSessionList(agentSessionDTO); | ||
try { | ||
if (agentSessionList != null) { | ||
HttpHeaders headers = new HttpHeaders(); | ||
headers.add("fileName", "Oturum Raporu_" + new SimpleDateFormat("dd_MM_yyyy_HH:mm:ss.SSS").format(new Date()) + ".xlsx"); | ||
headers.setContentType(MediaType.parseMediaType("application/csv")); | ||
headers.setCacheControl("must-revalidate, post-check=0, pre-check=0"); | ||
byte[] excelContent = excelService.generateUserSessionReport(agentSessionList.getContent()); | ||
return new ResponseEntity<byte[]>(excelContent, headers, HttpStatus.OK); | ||
} | ||
else { | ||
HttpHeaders headers = new HttpHeaders(); | ||
headers.add("message", "Invalid session type: " + agentSessionDTO.getSessionType()); | ||
return ResponseEntity | ||
.status(HttpStatus.BAD_REQUEST) | ||
.headers(headers) | ||
.build(); | ||
} | ||
} catch (Exception e) { | ||
logger.error("Error occured while creating excel report Error: ." + e.getMessage()); | ||
HttpHeaders headers = new HttpHeaders(); | ||
headers.add("message", "Error occured while creating excel report. Error: " + e.getMessage()); | ||
return ResponseEntity | ||
.status(HttpStatus.EXPECTATION_FAILED) | ||
.headers(headers) | ||
.build(); | ||
} | ||
} | ||
} |
Oops, something went wrong.