Compare commits
11 Commits
main
...
publicendp
Author | SHA1 | Date |
---|---|---|
Kavishka Madhusankha | 3694a0cf0e | 12 hours ago |
Kavishka Madhusankha | 0f988390ab | 2 days ago |
Kavishka Madhusankha | e7c633e10d | 2 days ago |
Kavishka Madhusankha | 2255ffe2f9 | 2 days ago |
Kavishka Madhusankha | d244c59f8e | 3 days ago |
Kavishka Madhusankha | 3a9dcb430e | 3 days ago |
Kavishka Madhusankha | 40af45a650 | 4 days ago |
Kavishka Madhusankha | 7ac7a535ef | 4 days ago |
Kavishka Madhusankha | 52d68cd33f | 7 days ago |
Kavishka Madhusankha | 9f181d088a | 1 week ago |
Kavishka Madhusankha | fdbae4bd57 | 1 week ago |
@ -0,0 +1,24 @@
|
||||
package com.example.Public.Configuration.config;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.FieldError;
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestControllerAdvice
|
||||
public class GlobalExceptionHandler {
|
||||
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||
public ResponseEntity<?> handleValidationExceptions(MethodArgumentNotValidException ex) {
|
||||
List<String> errors = ex.getBindingResult()
|
||||
.getAllErrors()
|
||||
.stream()
|
||||
.map(error -> ((FieldError) error).getField() + ": " + error.getDefaultMessage())
|
||||
.collect(Collectors.toList());
|
||||
return new ResponseEntity<>(errors, HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright (C) 2018 - 2024 Entgra (Pvt) Ltd, Inc - All Rights Reserved.
|
||||
*
|
||||
* Unauthorised copying/redistribution of this file, via any medium is strictly prohibited.
|
||||
*
|
||||
* Licensed under the Entgra Commercial License, Version 1.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://entgra.io/licenses/entgra-commercial/1.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package com.example.Public.Configuration.controller;
|
||||
|
||||
import com.example.Public.Configuration.dto.DeviceConfigDto;
|
||||
import com.example.Public.Configuration.dto.EnrolmentRequestDTO;
|
||||
import com.example.Public.Configuration.model.Device;
|
||||
import com.example.Public.Configuration.model.DeviceConfig;
|
||||
import com.example.Public.Configuration.response.Response;
|
||||
import com.example.Public.Configuration.service.impl.DeviceConfigServiceImpl;
|
||||
import com.example.Public.Configuration.service.impl.DeviceServiceImpl;
|
||||
import com.google.gson.Gson;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/device-config")
|
||||
@Validated
|
||||
public class DeviceConfigController {
|
||||
@Autowired
|
||||
private DeviceConfigServiceImpl deviceConfigService;
|
||||
@Autowired
|
||||
private DeviceServiceImpl deviceServiceImpl;
|
||||
|
||||
|
||||
|
||||
@PostMapping("/")
|
||||
public ResponseEntity<?> createDeviceConfigProfile(@Valid @RequestBody DeviceConfigDto deviceConfig) {
|
||||
Device configDevice = deviceServiceImpl.getDeviceByImei(deviceConfig.getConfigProfile().getImei());
|
||||
Gson ConfigProfile = new Gson();
|
||||
String profileJson = ConfigProfile.toJson(deviceConfig.getConfigProfile());
|
||||
DeviceConfig newConfig = new DeviceConfig();
|
||||
newConfig.setConfigId(deviceConfig.getConfigId());
|
||||
newConfig.setConfigProfile(profileJson);
|
||||
newConfig.setDevice(configDevice);
|
||||
newConfig.setConfigContent(deviceConfig.getConfigContent());
|
||||
deviceConfigService.saveConfigProfile(newConfig);
|
||||
return new ResponseEntity<>(profileJson, HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@GetMapping("/")
|
||||
public List<DeviceConfig> getConfigsDevices() {
|
||||
return deviceConfigService.getAllDeviceConfigs();
|
||||
}
|
||||
|
||||
@GetMapping("/{configId}")
|
||||
public ResponseEntity<?> fetchConfigByConfigId(@PathVariable int configId) {
|
||||
DeviceConfig deviceConfig1 = deviceConfigService.getConfigProfileByConfigId(configId);
|
||||
if (deviceConfig1 == null) {
|
||||
return new ResponseEntity<>(new Response(HttpStatus.NOT_FOUND.value(),
|
||||
"No Device found for Config ID: +configId"), HttpStatus.NOT_FOUND);
|
||||
}
|
||||
return new ResponseEntity<>(deviceConfig1, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PutMapping("/{configId}")
|
||||
public ResponseEntity<?> updateDeviceDetails(@PathVariable int configId, @RequestBody DeviceConfig deviceConfig) {
|
||||
DeviceConfig updateConfig = deviceConfigService.getConfigProfileByConfigId(configId);
|
||||
if (updateConfig == null) {
|
||||
deviceConfigService.UpdateConfigDetails(deviceConfig);
|
||||
return new ResponseEntity<>(new Response(HttpStatus.NOT_FOUND.value(),
|
||||
"No Device found for Config ID: +configId"), HttpStatus.NOT_FOUND);
|
||||
}
|
||||
return new ResponseEntity<>(new Response(HttpStatus.OK.value(),
|
||||
"Device Config updated successfully"), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{configId}")
|
||||
public ResponseEntity<?> deleteConfigConfigId(@PathVariable int configId) {
|
||||
DeviceConfig deleteConfig = deviceConfigService.getConfigProfileByConfigId(configId);
|
||||
if (deleteConfig == null) {
|
||||
deviceConfigService.deleteConfigProfile(configId);
|
||||
return new ResponseEntity<>(new Response(HttpStatus.NOT_FOUND.value(),
|
||||
"No Device found for Config ID: +configId"), HttpStatus.NOT_FOUND);
|
||||
}
|
||||
return new ResponseEntity<>(new Response(HttpStatus.OK.value(),
|
||||
"Device Config deleted successfully"), HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Copyright (C) 2018 - 2024 Entgra (Pvt) Ltd, Inc - All Rights Reserved.
|
||||
*
|
||||
* Unauthorised copying/redistribution of this file, via any medium is strictly prohibited.
|
||||
*
|
||||
* Licensed under the Entgra Commercial License, Version 1.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://entgra.io/licenses/entgra-commercial/1.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package com.example.Public.Configuration.controller;
|
||||
|
||||
import com.example.Public.Configuration.dao.DeviceDao;
|
||||
import com.example.Public.Configuration.dao.EnrolmentRequestLogDao;
|
||||
import com.example.Public.Configuration.dto.DeviceConfigDto;
|
||||
import com.example.Public.Configuration.dto.EnrolmentRequestDTO;
|
||||
import com.example.Public.Configuration.model.Device;
|
||||
import com.example.Public.Configuration.model.DeviceConfig;
|
||||
import com.example.Public.Configuration.model.EnrolmentRequestLog;
|
||||
import com.example.Public.Configuration.response.Response;
|
||||
import com.example.Public.Configuration.service.impl.DeviceConfigServiceImpl;
|
||||
import com.example.Public.Configuration.service.impl.DeviceServiceImpl;
|
||||
import com.example.Public.Configuration.service.impl.EnrolmentRequestServiceImpl;
|
||||
import com.google.gson.Gson;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/enrolment-request")
|
||||
@Validated
|
||||
public class EnrolmentRequestController {
|
||||
|
||||
@Autowired
|
||||
private DeviceServiceImpl deviceServiceImpl;
|
||||
private EnrolmentRequestServiceImpl enrolmentRequestService;
|
||||
private DeviceConfigServiceImpl deviceConfigServiceImpl;
|
||||
private DeviceConfig deviceConfig;
|
||||
private DeviceConfigDto deviceConfigDto;
|
||||
|
||||
|
||||
|
||||
@PostMapping("/") // add a new device to the database.
|
||||
public ResponseEntity<?> createEnrolmentRequest(@Valid @RequestBody EnrolmentRequestDTO enrolmentRequestLog) {
|
||||
|
||||
Device deviceEnrolment = deviceServiceImpl.getDeviceByImei(enrolmentRequestLog.getImei());
|
||||
DeviceConfig configProfile = deviceConfigServiceImpl.getConfigProfileByProfileName(String.valueOf(deviceConfigDto.getConfigProfile()));
|
||||
|
||||
Gson payload = new Gson();
|
||||
String ENROLMENT_REQUEST = payload.toJson(enrolmentRequestLog);
|
||||
EnrolmentRequestLog enrolmentRequest = new EnrolmentRequestLog();
|
||||
enrolmentRequest.setEnrolmentRequest(ENROLMENT_REQUEST);
|
||||
enrolmentRequest.setDevice(deviceEnrolment);
|
||||
enrolmentRequest.setReceivedAtTime(Instant.now().toEpochMilli());
|
||||
enrolmentRequestService.saveEnrolmentRequest(enrolmentRequest);
|
||||
|
||||
return new ResponseEntity<>(deviceEnrolment, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/")
|
||||
public List<EnrolmentRequestLog> getDevicesByRequests() {
|
||||
return enrolmentRequestService.getAllEnrolmentRequests();
|
||||
}
|
||||
|
||||
@GetMapping("/{requestId}")
|
||||
public ResponseEntity<?> fetchEnrolmentRequest(@PathVariable int requestId) {
|
||||
EnrolmentRequestLog deviceEnrolment = enrolmentRequestService.getEnrolmentRequestByRequestId(requestId);
|
||||
if (deviceEnrolment == null) {
|
||||
return new ResponseEntity<>(new Response(HttpStatus.NOT_FOUND.value(), "No Device found for Enrolment Request : +imei"), HttpStatus.NOT_FOUND);
|
||||
}
|
||||
return new ResponseEntity<>(deviceEnrolment, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PutMapping("/{requestId}")
|
||||
public ResponseEntity<?> updateEnrolmentRequestLog(@PathVariable int requestId, @RequestBody EnrolmentRequestLog enrolmentRequestLog) {
|
||||
EnrolmentRequestLog updatedEnrolment = enrolmentRequestService.getEnrolmentRequestByRequestId(requestId);
|
||||
if (updatedEnrolment == null) {
|
||||
enrolmentRequestService.updateEnrolmentRequest(enrolmentRequestLog);
|
||||
return new ResponseEntity<>(new Response(HttpStatus.NOT_FOUND.value(), "No Device found for Enrolment Request : +imei"), HttpStatus.NOT_FOUND);
|
||||
}
|
||||
return new ResponseEntity<>(new Response(HttpStatus.OK.value(), "Device updated successfully"), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{requestId}")
|
||||
public ResponseEntity<?> deleteEnrolmentRequestId(@PathVariable int requestId) {
|
||||
EnrolmentRequestLog deletedEnrolment = enrolmentRequestService.getEnrolmentRequestByRequestId(requestId);
|
||||
if (deletedEnrolment == null) {
|
||||
enrolmentRequestService.deleteEnrolmentRequest(requestId);
|
||||
return new ResponseEntity<>(new Response(HttpStatus.NOT_FOUND.value(), "No Device found for Enrolment Request : +requestId"), HttpStatus.NOT_FOUND);
|
||||
}
|
||||
return new ResponseEntity<>(new Response(HttpStatus.OK.value(), "Enrolment Request deleted successfully"), HttpStatus.OK);
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (C) 2018 - 2024 Entgra (Pvt) Ltd, Inc - All Rights Reserved.
|
||||
*
|
||||
* Unauthorised copying/redistribution of this file, via any medium is strictly prohibited.
|
||||
*
|
||||
* Licensed under the Entgra Commercial License, Version 1.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://entgra.io/licenses/entgra-commercial/1.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package com.example.Public.Configuration.dao;
|
||||
|
||||
import com.example.Public.Configuration.model.DeviceConfig;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
|
||||
@Repository
|
||||
public interface DeviceConfigDao extends JpaRepository<DeviceConfig, Integer> {
|
||||
|
||||
DeviceConfig findByConfigId(int configId);
|
||||
|
||||
DeviceConfig findDeviceConfigByConfigProfile(String configProfile);
|
||||
|
||||
void deleteByConfigId(int configId);
|
||||
|
||||
}
|
@ -1,7 +1,31 @@
|
||||
/*
|
||||
* Copyright (C) 2018 - 2024 Entgra (Pvt) Ltd, Inc - All Rights Reserved.
|
||||
*
|
||||
* Unauthorised copying/redistribution of this file, via any medium is strictly prohibited.
|
||||
*
|
||||
* Licensed under the Entgra Commercial License, Version 1.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://entgra.io/licenses/entgra-commercial/1.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package com.example.Public.Configuration.dao;
|
||||
|
||||
import com.example.Public.Configuration.model.Device;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface DeviceDao extends JpaRepository<Device, Long> {
|
||||
public interface DeviceDao extends JpaRepository<Device, Integer> {
|
||||
|
||||
|
||||
Device findByImei(String imei);
|
||||
|
||||
Device findByDeviceId(int deviceId);
|
||||
}
|
||||
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C) 2018 - 2024 Entgra (Pvt) Ltd, Inc - All Rights Reserved.
|
||||
*
|
||||
* Unauthorised copying/redistribution of this file, via any medium is strictly prohibited.
|
||||
*
|
||||
* Licensed under the Entgra Commercial License, Version 1.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://entgra.io/licenses/entgra-commercial/1.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package com.example.Public.Configuration.dao;
|
||||
|
||||
import com.example.Public.Configuration.model.EnrolmentRequestLog;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface EnrolmentRequestLogDao extends JpaRepository<EnrolmentRequestLog, Integer> {
|
||||
|
||||
// EnrolmentRequestLog findByImei(String imei) ;
|
||||
|
||||
|
||||
EnrolmentRequestLog findByRequestId(int requestId);
|
||||
|
||||
void deleteByRequestId(int requestId);
|
||||
|
||||
//static EnrolmentRequestLog findEnrolmentRequestLogByImei(@NotBlank(message = "IMEI cannot be blank") String enrolmentRequestLog);
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package com.example.Public.Configuration.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class DeviceConfigDto {
|
||||
|
||||
private int configId;
|
||||
private ConfigProfile configProfile;
|
||||
private String configContent;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public static class ConfigProfile {
|
||||
|
||||
@NotBlank(message = "IMEI cannot be blank")
|
||||
private String imei;
|
||||
private String phn_no_rx_1;
|
||||
private String phn_no_rx_2;
|
||||
private String phn_no_tx_1;
|
||||
private String gprs_apn;
|
||||
private String nbiot_apn;
|
||||
private String iot_server_host_add;
|
||||
private String iot_server_port;
|
||||
private String listning_port;
|
||||
private String network_mode;
|
||||
private String sms_tx;
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package com.example.Public.Configuration.dto;
|
||||
|
||||
import com.example.Public.Configuration.model.Device;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class EnrolmentRequestDTO {
|
||||
@NotBlank(message = "IMEI cannot be blank")
|
||||
private String imei;
|
||||
@NotBlank(message = "IP Address cannot be blank")
|
||||
private String ipAddress;
|
||||
private String subTypeId;
|
||||
private String smsPIN;
|
||||
private int mfwVersion;
|
||||
private int rssi;
|
||||
private String network;
|
||||
private int comTypeId;
|
||||
private String cellId;
|
||||
private String lac;
|
||||
private int sysTick;
|
||||
private String meFwVersion;
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (C) 2018 - 2024 Entgra (Pvt) Ltd, Inc - All Rights Reserved.
|
||||
*
|
||||
* Unauthorised copying/redistribution of this file, via any medium is strictly prohibited.
|
||||
*
|
||||
* Licensed under the Entgra Commercial License, Version 1.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://entgra.io/licenses/entgra-commercial/1.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package com.example.Public.Configuration.model;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
@Table(name = "device_config-profile")
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
@Setter
|
||||
public class DeviceConfig {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "config_id")
|
||||
private int configId;
|
||||
|
||||
@Column(name = "config_profile")
|
||||
private String configProfile;
|
||||
|
||||
@Column(name = "config_content")
|
||||
private String configContent;
|
||||
|
||||
@OneToOne(cascade = CascadeType.ALL)
|
||||
@JoinColumn(name = "device_id", referencedColumnName = "device_id")
|
||||
private Device device;
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (C) 2018 - 2024 Entgra (Pvt) Ltd, Inc - All Rights Reserved.
|
||||
*
|
||||
* Unauthorised copying/redistribution of this file, via any medium is strictly prohibited.
|
||||
*
|
||||
* Licensed under the Entgra Commercial License, Version 1.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://entgra.io/licenses/entgra-commercial/1.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package com.example.Public.Configuration.model;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
@Table(name = "enrolment_request_log")
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class EnrolmentRequestLog {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "enrolment_id")
|
||||
private int requestId;
|
||||
|
||||
@Column(name = "enrolment_request")
|
||||
private String EnrolmentRequest;
|
||||
|
||||
@Column(name = "response_time")
|
||||
private long receivedAtTime;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "device_id", nullable = false)
|
||||
private Device device;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (C) 2018 - 2024 Entgra (Pvt) Ltd, Inc - All Rights Reserved.
|
||||
*
|
||||
* Unauthorised copying/redistribution of this file, via any medium is strictly prohibited.
|
||||
*
|
||||
* Licensed under the Entgra Commercial License, Version 1.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://entgra.io/licenses/entgra-commercial/1.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package com.example.Public.Configuration.response;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Response {
|
||||
|
||||
|
||||
|
||||
private int code;
|
||||
private String message;
|
||||
|
||||
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package com.example.Public.Configuration.response;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
@AllArgsConstructor
|
||||
|
||||
public class ResponseMessage {
|
||||
|
||||
private int status;
|
||||
private String message;
|
||||
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C) 2018 - 2024 Entgra (Pvt) Ltd, Inc - All Rights Reserved.
|
||||
*
|
||||
* Unauthorised copying/redistribution of this file, via any medium is strictly prohibited.
|
||||
*
|
||||
* Licensed under the Entgra Commercial License, Version 1.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://entgra.io/licenses/entgra-commercial/1.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package com.example.Public.Configuration.service;
|
||||
|
||||
import com.example.Public.Configuration.model.DeviceConfig;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface DeviceConfigService {
|
||||
|
||||
DeviceConfig saveConfigProfile(DeviceConfig deviceConfig);
|
||||
|
||||
List<DeviceConfig> getAllDeviceConfigs();
|
||||
|
||||
DeviceConfig getByConfigId(String configId);
|
||||
|
||||
DeviceConfig UpdateConfigDetails(DeviceConfig deviceConfig);
|
||||
|
||||
String deleteConfigProfile(String configId);
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (C) 2018 - 2024 Entgra (Pvt) Ltd, Inc - All Rights Reserved.
|
||||
*
|
||||
* Unauthorised copying/redistribution of this file, via any medium is strictly prohibited.
|
||||
*
|
||||
* Licensed under the Entgra Commercial License, Version 1.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://entgra.io/licenses/entgra-commercial/1.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package com.example.Public.Configuration.service;
|
||||
|
||||
import com.example.Public.Configuration.model.EnrolmentRequestLog;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface EnrolmentRequestService {
|
||||
|
||||
EnrolmentRequestLog saveEnrolmentRequest(EnrolmentRequestLog enrolmentRequestLog);
|
||||
|
||||
List<EnrolmentRequestLog> getEnrolmentRequests();
|
||||
|
||||
EnrolmentRequestLog findEnrolmentRequestLogByImei(String imei);
|
||||
|
||||
EnrolmentRequestLog getEnrolmentRequestByRequestId(String imei);
|
||||
|
||||
EnrolmentRequestLog updateEnrolmentRequest(EnrolmentRequestLog enrolmentRequestLog);
|
||||
|
||||
String deleteEnrolmentRequest(String imei);
|
||||
}
|
||||
|
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (C) 2018 - 2024 Entgra (Pvt) Ltd, Inc - All Rights Reserved.
|
||||
*
|
||||
* Unauthorised copying/redistribution of this file, via any medium is strictly prohibited.
|
||||
*
|
||||
* Licensed under the Entgra Commercial License, Version 1.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://entgra.io/licenses/entgra-commercial/1.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package com.example.Public.Configuration.service.impl;
|
||||
|
||||
import com.example.Public.Configuration.dao.DeviceConfigDao;
|
||||
import com.example.Public.Configuration.model.DeviceConfig;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class DeviceConfigServiceImpl {
|
||||
|
||||
@Autowired
|
||||
private DeviceConfigDao deviceConfigDao;
|
||||
|
||||
public void saveConfigProfile(DeviceConfig deviceConfig) {
|
||||
deviceConfigDao.save(deviceConfig); // use to save the device details to the database
|
||||
}//autowire the deviceDao object
|
||||
|
||||
|
||||
public List<DeviceConfig> getAllDeviceConfigs() {
|
||||
return deviceConfigDao.findAll(); // use to command using the deviceDao object to get all the device details from the database
|
||||
}
|
||||
|
||||
public DeviceConfig getConfigProfileByConfigId(int configId) {
|
||||
return deviceConfigDao.findByConfigId(configId); // use to get the device details by id
|
||||
}
|
||||
public DeviceConfig getConfigProfileByProfileName(String configProfile) {
|
||||
return deviceConfigDao.findDeviceConfigByConfigProfile(configProfile); // use to get the device details by profile name
|
||||
|
||||
}
|
||||
//
|
||||
// public DeviceConfig getConfigProfileByDeviceId(int deviceId) {
|
||||
// return deviceConfigDao.findDeviceConfigByImei(deviceId); // use to get the device details by profile name
|
||||
// }
|
||||
public void UpdateConfigDetails(DeviceConfig deviceConfig) {
|
||||
DeviceConfig updatedConfig = deviceConfigDao.findByConfigId(deviceConfig.getConfigId());
|
||||
if (updatedConfig != null) {
|
||||
updatedConfig.setConfigProfile(deviceConfig.getConfigProfile());
|
||||
updatedConfig.setConfigContent(deviceConfig.getConfigContent());
|
||||
deviceConfigDao.save(updatedConfig);
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteConfigProfile(int configId) {
|
||||
deviceConfigDao.deleteByConfigId(configId); // use to delete the device details by id
|
||||
}
|
||||
}
|
@ -1,73 +1,75 @@
|
||||
/*
|
||||
* Copyright (C) 2018 - 2024 Entgra (Pvt) Ltd, Inc - All Rights Reserved.
|
||||
*
|
||||
* Unauthorised copying/redistribution of this file, via any medium is strictly prohibited.
|
||||
*
|
||||
* Licensed under the Entgra Commercial License, Version 1.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://entgra.io/licenses/entgra-commercial/1.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package com.example.Public.Configuration.service.impl;
|
||||
|
||||
import com.example.Public.Configuration.dao.DeviceDao;
|
||||
import com.example.Public.Configuration.model.Device;
|
||||
import com.example.Public.Configuration.service.DeviceService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Service
|
||||
public class DeviceServiceImpl implements DeviceService {
|
||||
|
||||
public class DeviceServiceImpl {
|
||||
|
||||
@Autowired
|
||||
private DeviceDao deviceDao;
|
||||
private DeviceDao deviceDao; //autowire the deviceDao object
|
||||
|
||||
public Device saveDevice(Device device) {
|
||||
return deviceDao.save(device);
|
||||
public Device saveDetails(Device device) { //used to save the device details in the database
|
||||
deviceDao.save(device);
|
||||
new ResponseEntity<>(device, HttpStatus.CREATED);
|
||||
return device;
|
||||
}
|
||||
|
||||
public List<Device> getAllDevices() {
|
||||
return deviceDao.findAll();
|
||||
|
||||
return deviceDao.findAll(); // use to command using
|
||||
}
|
||||
|
||||
@Override
|
||||
public Device getDeviceById(long device_id) {
|
||||
return null;
|
||||
public Device getDeviceById(int deviceId) {
|
||||
return deviceDao.findById(deviceId).orElse(null); // use to get the device details by id
|
||||
}
|
||||
|
||||
@Override
|
||||
public Device updateDevice(Device device) {
|
||||
return null;
|
||||
public Device getDeviceByImei(String imei) {
|
||||
return deviceDao.findByImei(imei);
|
||||
// use to get the device details by id
|
||||
}
|
||||
//
|
||||
// public Device getDeviceByDeviceId(int deviceId) {
|
||||
// return deviceDao.findByDeviceId(deviceId);
|
||||
// // use to get the device details by id
|
||||
// }
|
||||
|
||||
@Override
|
||||
public String deleteDevice(long device_id) {
|
||||
return "";
|
||||
}
|
||||
|
||||
public Device getDeviceById(Long device_id) {
|
||||
return deviceDao.findById(device_id).orElse(null);
|
||||
}
|
||||
public Device UpdateDevice(Device device) { //used to update the device details in the database
|
||||
Device updatedDevice = deviceDao.findById(device.getDevice_id()).orElse(null); //This command is used to get the device details by id
|
||||
public void UpdateDetailsById(Device device) { //used to update the device details in the database
|
||||
Device updatedDevice = deviceDao.findById(device.getDeviceId()).orElse(null); //This command is used to get the device details by id
|
||||
|
||||
if (updatedDevice != null) { // device details are present in the database then update the device details
|
||||
updatedDevice.setImei(device.getImei());
|
||||
updatedDevice.setDeviceId(device.getDeviceId());
|
||||
updatedDevice.setDevice_model(device.getDevice_model());
|
||||
updatedDevice.setUpdate_time(device.getUpdate_time());
|
||||
updatedDevice.setNetwork(device.getNetwork());
|
||||
updatedDevice.setMFW_Version(device.getMFW_Version());
|
||||
updatedDevice.setLAC(device.getLAC());
|
||||
updatedDevice.setDevice_organization(device.getDevice_organization());
|
||||
updatedDevice.setMEFW_Version(device.getMEFW_Version());
|
||||
updatedDevice.setRSSI(device.getRSSI());
|
||||
deviceDao.save(updatedDevice);
|
||||
}
|
||||
return updatedDevice;
|
||||
}
|
||||
public String deleteDevice(Long device_id) {
|
||||
deviceDao.deleteById(device_id);
|
||||
return "deleted " +device_id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void deleteDevice(int deviceId) {//used to delete the device details from the database
|
||||
deviceDao.deleteById(deviceId);//delete the device details by id
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (C) 2018 - 2024 Entgra (Pvt) Ltd, Inc - All Rights Reserved.
|
||||
*
|
||||
* Unauthorised copying/redistribution of this file, via any medium is strictly prohibited.
|
||||
*
|
||||
* Licensed under the Entgra Commercial License, Version 1.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://entgra.io/licenses/entgra-commercial/1.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package com.example.Public.Configuration.service.impl;
|
||||
|
||||
import com.example.Public.Configuration.dao.EnrolmentRequestLogDao;
|
||||
import com.example.Public.Configuration.model.EnrolmentRequestLog;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class EnrolmentRequestServiceImpl {
|
||||
|
||||
@Autowired
|
||||
private EnrolmentRequestLogDao enrolmentRequestLogDao;
|
||||
|
||||
public void saveEnrolmentRequest(@RequestBody EnrolmentRequestLog enrolmentRequestLog) {
|
||||
enrolmentRequestLogDao.save(enrolmentRequestLog);
|
||||
}
|
||||
|
||||
public List<EnrolmentRequestLog> getAllEnrolmentRequests() {
|
||||
return enrolmentRequestLogDao.findAll();
|
||||
}
|
||||
|
||||
public EnrolmentRequestLog getEnrolmentRequestByRequestId(int requestId) {
|
||||
return enrolmentRequestLogDao.findByRequestId(requestId);
|
||||
|
||||
}
|
||||
|
||||
public void updateEnrolmentRequest(EnrolmentRequestLog enrolmentRequestLog) { //used to update the device details in the database
|
||||
EnrolmentRequestLog updatedEnrolmentRequest = enrolmentRequestLogDao.findByRequestId
|
||||
(enrolmentRequestLog.getRequestId()); //This command is used to get the device details by id
|
||||
|
||||
if (updatedEnrolmentRequest != null) { // device details are present in the database then update the device details
|
||||
updatedEnrolmentRequest.setRequestId(Integer.parseInt(enrolmentRequestLog.getEnrolmentRequest()));
|
||||
updatedEnrolmentRequest.setReceivedAtTime(enrolmentRequestLog.getReceivedAtTime());
|
||||
enrolmentRequestLogDao.save(updatedEnrolmentRequest);
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteEnrolmentRequest(int requestId) {
|
||||
enrolmentRequestLogDao.deleteByRequestId(requestId);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue