init
This commit is contained in:
parent
e30890b783
commit
9dafa6c956
|
|
@ -0,0 +1,3 @@
|
|||
[
|
||||
|
||||
]
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
package eu.csc.ODPAppVehOwnServer.persistence.api;
|
||||
|
||||
public interface IDevice {
|
||||
|
||||
String getSerialnumber();
|
||||
|
||||
}
|
||||
|
|
@ -1,12 +1,13 @@
|
|||
package eu.csc.ODPAppVehOwnServer.persistence.entity;
|
||||
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.entity.customer.CustomerDeviceEntity;
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.entity.data.VehicleModelEntity;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.*;
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
|
|
@ -28,6 +29,8 @@ public class UserEntity extends AbstractEntity{
|
|||
|
||||
|
||||
|
||||
@OneToMany(fetch = FetchType.EAGER, mappedBy = "user", cascade = CascadeType.ALL)
|
||||
private List<CustomerDeviceEntity>customerDeviceEntities;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
package eu.csc.ODPAppVehOwnServer.persistence.entity.customer;
|
||||
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.entity.AbstractEntity;
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.entity.UserEntity;
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.entity.data.DeviceEntity;
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.entity.data.VehicleBrandEntity;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
|
||||
@MappedSuperclass
|
||||
public abstract class AbstractCustomerEntity extends AbstractEntity {
|
||||
@ManyToOne
|
||||
@JoinColumn(nullable = false, name = "user_id", insertable = false, updatable = false)
|
||||
private UserEntity user;
|
||||
|
||||
@Column(name = "user_id", nullable = false)
|
||||
private Long user_id;
|
||||
public void setUser(UserEntity user) {
|
||||
this.user = user;
|
||||
this.user_id = user != null ? user.getId(): null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
package eu.csc.ODPAppVehOwnServer.persistence.entity.customer;
|
||||
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.entity.AbstractEntity;
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.entity.UserEntity;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
|
||||
@Entity
|
||||
@Table(name = "tcustomer_devices")
|
||||
public class CustomerDeviceEntity extends AbstractCustomerEntity {
|
||||
|
||||
|
||||
|
||||
@Column(name = "serialnumber", unique = true, nullable = false)
|
||||
private String serialnumber;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
package eu.csc.ODPAppVehOwnServer.persistence.entity.customer;
|
||||
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.entity.AbstractEntity;
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.entity.UserEntity;
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.entity.data.DeviceEntity;
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.entity.data.VehicleModelEntity;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
|
||||
@Entity
|
||||
@Table(name = "tcustomer_vehicles")
|
||||
public class CustomerVehicleEntity extends AbstractCustomerEntity {
|
||||
|
||||
|
||||
private String vin;
|
||||
private String brand;
|
||||
private String model;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(nullable = true, name = "cd_id", insertable = false, updatable = false)
|
||||
|
||||
private CustomerDeviceEntity activeCustomerDevice;
|
||||
|
||||
@Column(name = "cd_id", nullable = true)
|
||||
private Long cd_id;
|
||||
|
||||
public void addVehicleInfo(VehicleModelEntity item){
|
||||
this.brand = item.getBrand().getBrandId();
|
||||
this.model = item.getModel();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
package eu.csc.ODPAppVehOwnServer.persistence.entity.data;
|
||||
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.entity.AbstractEntity;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
|
||||
@Entity
|
||||
@Table(name = "tdevices_articles")
|
||||
|
||||
@ToString(callSuper = true, onlyExplicitlyIncluded = true)
|
||||
//@ToString(callSuper = true, onlyExplicitlyIncluded = true)
|
||||
public class DeviceArticleEntity extends AbstractEntity {
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(nullable = true, name = "device_id", insertable = false, updatable = false)
|
||||
private DeviceEntity device;
|
||||
|
||||
@Column(name = "device_id", nullable = false)
|
||||
private Long device_id;
|
||||
|
||||
@Column(name = "serialnumber", unique = true, nullable = false)
|
||||
private String serialNumber;
|
||||
|
||||
|
||||
public void setDevice(DeviceEntity device) {
|
||||
this.device = device;
|
||||
this.device_id = device != null ? device.getId(): null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
package eu.csc.ODPAppVehOwnServer.persistence.entity.data;
|
||||
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.entity.AbstractEntity;
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.entity.customer.AbstractCustomerEntity;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
|
||||
@Entity
|
||||
@Table(name = "tdevices")
|
||||
|
||||
@ToString(callSuper = true, onlyExplicitlyIncluded = false)
|
||||
//@ToString(callSuper = true, onlyExplicitlyIncluded = true)
|
||||
public class DeviceEntity extends AbstractEntity {
|
||||
|
||||
@Column(name = "devicenumber", unique = true, nullable = false)
|
||||
private String devicenumber;
|
||||
|
||||
|
||||
@Column(nullable = false)
|
||||
private String name;
|
||||
@Column(nullable = true)
|
||||
private String manufacturer;
|
||||
|
||||
@OneToMany(fetch = FetchType.EAGER, mappedBy = "device", cascade = CascadeType.ALL)
|
||||
private List<DeviceArticleEntity> deviceEntities;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -6,9 +6,8 @@ import lombok.NoArgsConstructor;
|
|||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.*;
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
|
|
@ -17,7 +16,8 @@ import javax.persistence.Table;
|
|||
@Entity
|
||||
@Table(name = "tvehicle_brands")
|
||||
|
||||
@ToString(callSuper = true)
|
||||
@ToString(callSuper = true, onlyExplicitlyIncluded = false)
|
||||
//@ToString(callSuper = true, onlyExplicitlyIncluded = true)
|
||||
public class VehicleBrandEntity extends AbstractEntity {
|
||||
|
||||
@Column(name = "brand_id", unique = true, nullable = false)
|
||||
|
|
@ -26,4 +26,7 @@ public class VehicleBrandEntity extends AbstractEntity {
|
|||
@Column(nullable = false)
|
||||
private String name;
|
||||
|
||||
@OneToMany(fetch = FetchType.EAGER, mappedBy = "brand", cascade = CascadeType.ALL)
|
||||
private List<VehicleModelEntity> modelEntities;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
package eu.csc.ODPAppVehOwnServer.persistence.respository;
|
||||
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.entity.UserEntity;
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.entity.customer.CustomerDeviceEntity;
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.entity.data.DeviceEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface CustomerDeviceRepository extends JpaRepository<CustomerDeviceEntity, Long> {
|
||||
|
||||
|
||||
List<CustomerDeviceEntity> findAllByUser(UserEntity user);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package eu.csc.ODPAppVehOwnServer.persistence.respository;
|
||||
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.entity.data.DeviceArticleEntity;
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.entity.data.DeviceEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface DeviceArticleRepository extends JpaRepository<DeviceArticleEntity, Long> {
|
||||
|
||||
|
||||
List<DeviceArticleEntity> findByDevice(DeviceEntity s);
|
||||
|
||||
int countAllByDeviceDevicenumber(String device);
|
||||
|
||||
Optional<DeviceArticleEntity> findByDeviceDevicenumberAndSerialNumber(String brand, String name);
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package eu.csc.ODPAppVehOwnServer.persistence.respository;
|
||||
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.entity.data.DeviceEntity;
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.entity.data.VehicleModelEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface DeviceRepository extends JpaRepository<DeviceEntity, Long> {
|
||||
|
||||
|
||||
Optional<DeviceEntity> findByDevicenumber(String s);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
package eu.csc.ODPAppVehOwnServer.persistence.services;
|
||||
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.entity.data.DeviceArticleEntity;
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.entity.data.DeviceEntity;
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.respository.DeviceArticleRepository;
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.respository.DeviceRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public class CustomerService {
|
||||
|
||||
@Autowired
|
||||
private UtilsService utilsService;
|
||||
|
||||
@Autowired
|
||||
private DeviceService deviceService;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
package eu.csc.ODPAppVehOwnServer.persistence.services;
|
||||
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.entity.data.DeviceArticleEntity;
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.entity.data.DeviceEntity;
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.entity.data.VehicleBrandEntity;
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.entity.data.VehicleModelEntity;
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.respository.DeviceArticleRepository;
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.respository.DeviceRepository;
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.respository.VehicleBrandRepository;
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.respository.VehicleModelRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public class DeviceService {
|
||||
|
||||
@Autowired
|
||||
private UtilsService utilsService;
|
||||
|
||||
@Autowired
|
||||
private DeviceRepository deviceRepository;
|
||||
@Autowired
|
||||
private DeviceArticleRepository deviceArticleRepository;
|
||||
|
||||
|
||||
public List<DeviceEntity> findAll() {
|
||||
return deviceRepository.findAll();
|
||||
}
|
||||
|
||||
public DeviceArticleEntity generateDeviceArticle(String device){
|
||||
|
||||
DeviceArticleEntity entity = new DeviceArticleEntity();
|
||||
|
||||
var oD = deviceRepository.findByDevicenumber(device);
|
||||
|
||||
|
||||
entity.setDevice(oD.get());
|
||||
|
||||
|
||||
entity.setSerialNumber(utilsService.getSerialnumber(deviceArticleRepository.countAllByDeviceDevicenumber(device)));
|
||||
deviceArticleRepository.save(entity);
|
||||
|
||||
return entity;
|
||||
|
||||
}
|
||||
|
||||
public DeviceArticleEntity generateDeviceArticle(String device, String serialnumber){
|
||||
|
||||
DeviceArticleEntity entity = new DeviceArticleEntity();
|
||||
|
||||
var oD = deviceRepository.findByDevicenumber(device);
|
||||
|
||||
|
||||
entity.setDevice(oD.get());
|
||||
|
||||
|
||||
entity.setSerialNumber(serialnumber);
|
||||
deviceArticleRepository.save(entity);
|
||||
|
||||
return entity;
|
||||
|
||||
}
|
||||
public Optional<DeviceArticleEntity> findByDeviceAndSerialnumber(String brand, String name){
|
||||
return deviceArticleRepository.findByDeviceDevicenumberAndSerialNumber(brand, name);
|
||||
}
|
||||
public DeviceEntity addDevice(String brand, String name, String manufacturer) {
|
||||
DeviceEntity item = new DeviceEntity();
|
||||
|
||||
item.setDevicenumber(brand);
|
||||
item.setName(name);
|
||||
item.setManufacturer(manufacturer);
|
||||
|
||||
return deviceRepository.save(item);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package eu.csc.ODPAppVehOwnServer.persistence.services;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
@Service
|
||||
public class UtilsService {
|
||||
public String getSerialnumber (int size) {
|
||||
|
||||
int serialNo = 000 + 1 + size;
|
||||
|
||||
Calendar cal = Calendar.getInstance();
|
||||
|
||||
int date = cal.get(Calendar.DATE);
|
||||
int month = cal.get(Calendar.MONTH) + 1;
|
||||
int year = cal.get(Calendar.YEAR);
|
||||
|
||||
return ""+year + month + date + serialNo;
|
||||
}
|
||||
}
|
||||
|
|
@ -36,7 +36,12 @@
|
|||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>dto</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependency> <dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>client</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
|||
|
||||
private static final RequestMatcher PUBLIC_URLS = new OrRequestMatcher(
|
||||
new AntPathRequestMatcher("/login"),
|
||||
new AntPathRequestMatcher("/devices/**"),
|
||||
new AntPathRequestMatcher("/vehicles/**"),
|
||||
new AntPathRequestMatcher("/registration/odpstudio")
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,149 @@
|
|||
package eu.csc.ODPAppVehOwnServer.controller;
|
||||
|
||||
import eu.csc.ODPAppVehOwnServer.models.data.ErrorResultDto;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
|
||||
import javax.persistence.EntityExistsException;
|
||||
import javax.persistence.EntityNotFoundException;
|
||||
import javax.persistence.PersistenceException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
|
||||
public abstract class AbstractRestController {
|
||||
|
||||
public static final int HTTP_STATUS_EXISTS = 601;
|
||||
public static final int HTTP_STATUS_NOT_FOUND = 604;
|
||||
|
||||
protected boolean checkIsInRule(HttpServletRequest request, String role){
|
||||
return request.isUserInRole(role);
|
||||
}
|
||||
|
||||
protected Authentication getLoggedInUser(){
|
||||
return SecurityContextHolder.getContext().getAuthentication();
|
||||
}
|
||||
|
||||
//region ExceptionHandling
|
||||
|
||||
|
||||
@ExceptionHandler(EntityNotFoundException.class)
|
||||
public ResponseEntity handleEntityNotFoundException(EntityNotFoundException ex) {
|
||||
return new ResponseEntity<>(ErrorResultDto.get(ex), HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
@ExceptionHandler(EntityExistsException.class)
|
||||
public ResponseEntity<?> handleEntityExistsException(EntityExistsException ex) {
|
||||
return ResponseEntity.status( HTTP_STATUS_EXISTS).body(ErrorResultDto.get(ex));
|
||||
}
|
||||
|
||||
|
||||
@ExceptionHandler(PersistenceException.class)
|
||||
public ResponseEntity handlePersistenceNotFoundException(PersistenceException ex) {
|
||||
return new ResponseEntity<>(ex.getMessage(), HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
|
||||
//endregion
|
||||
|
||||
//region RESPONSE CONTENT
|
||||
|
||||
protected ResponseEntity<Resource> getFileDownloadResponse(Resource file){
|
||||
|
||||
return ResponseEntity.ok().header(HttpHeaders.CONTENT_DISPOSITION,
|
||||
"attachment; filename=\"" +file.getFilename() + "\"").body(file);
|
||||
}
|
||||
|
||||
public ResponseEntity getErrorOkResponse(Exception ex) {
|
||||
return ResponseEntity.badRequest().body(new ErrorResultDto(ex.getMessage()));
|
||||
}
|
||||
|
||||
public ResponseEntity<?> getBadRequestResponse() {
|
||||
return ResponseEntity.badRequest().build();
|
||||
}
|
||||
|
||||
public <T> ResponseEntity<T> getSuccessResponse() {
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
public <T> ResponseEntity<T> getSuccessResponse(T content) {
|
||||
return ResponseEntity.ok(content);
|
||||
}
|
||||
public <T> ResponseEntity<T> getSuccessResponse(T content, HttpHeaders header) {
|
||||
return ResponseEntity.ok().headers(header).body(content);
|
||||
}
|
||||
|
||||
public <T> ResponseEntity<T> notImplementedResponse() {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
public ResponseEntity<?> getSuccessDeleteResponse(Object identifier) {
|
||||
|
||||
|
||||
return ResponseEntity.ok(identifier);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public <T> ResponseEntity<T> getEntityExistsResponse() {
|
||||
return ResponseEntity.status(HttpStatus.CONFLICT).build();
|
||||
}
|
||||
|
||||
public <T> ResponseEntity<?> getEntityExistsResponse(String what, String searchCriteria) {
|
||||
return ResponseEntity.status(HttpStatus.CONFLICT).body(new ErrorResultDto(String.format("[%s] [%s]", what, searchCriteria)));
|
||||
}
|
||||
|
||||
public <T> ResponseEntity<?> getNotFoundResponse(String what, Object searchCriteria) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(String.format("[%s] [%s]", what, searchCriteria));
|
||||
}
|
||||
|
||||
public <T> ResponseEntity<T> getNotSupportedResponse() {
|
||||
return ResponseEntity.status(HttpStatus.NOT_IMPLEMENTED).build();
|
||||
}
|
||||
public <T> ResponseEntity<T> getNotFoundResponse() {
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
|
||||
}
|
||||
|
||||
public <T> ResponseEntity<?> getBadRequestResponse(String what, String searchCriteria) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(String.format("[%s] [%s]", what, searchCriteria));
|
||||
}
|
||||
|
||||
|
||||
//endregion
|
||||
|
||||
/**
|
||||
protected void copyImageToRespone(HttpServletResponse response, EmbFileField image) {
|
||||
InputStream in = null;
|
||||
|
||||
if (image == null) {
|
||||
try {
|
||||
in = new FileInputStream(new File("src/main/resources/files/images/no_image_available.svg.png"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}else {
|
||||
in = new ByteArrayInputStream(image.getDbField());
|
||||
}
|
||||
|
||||
|
||||
if(in == null)
|
||||
return;
|
||||
|
||||
response.setContentType(MediaType.IMAGE_PNG_VALUE);
|
||||
try {
|
||||
IOUtils.copy(in, response.getOutputStream());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
**/
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
package eu.csc.ODPAppVehOwnServer.controller.data;
|
||||
|
||||
import eu.csc.ODPAppVehOwnServer.models.VehicleBrandDto;
|
||||
import eu.csc.ODPAppVehOwnServer.models.data.DeviceDto;
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.services.DeviceService;
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.services.VehicleService;
|
||||
import lombok.var;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("devices")
|
||||
public class DeviceController {
|
||||
|
||||
@Autowired
|
||||
private DeviceService deviceService;
|
||||
|
||||
@GetMapping
|
||||
|
||||
public ResponseEntity<List<DeviceDto>> showDevices() {
|
||||
|
||||
var items = new ArrayList<DeviceDto>();
|
||||
|
||||
for (var v : deviceService.findAll()
|
||||
) {
|
||||
|
||||
DeviceDto dto = new DeviceDto();
|
||||
dto.setName(v.getName());
|
||||
dto.setDevicenumber(v.getDevicenumber());
|
||||
dto.setId(v.getId());
|
||||
|
||||
items.add(dto);
|
||||
|
||||
}
|
||||
|
||||
|
||||
return ResponseEntity.ok(items);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -2,19 +2,45 @@ package eu.csc.ODPAppVehOwnServer.controller.data;
|
|||
|
||||
import eu.csc.ODPAppVehOwnServer.models.VehicleBrandDto;
|
||||
import eu.csc.ODPAppVehOwnServer.models.data.LanguageDto;
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.services.VehicleService;
|
||||
import lombok.var;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("vehicles")
|
||||
public class VehicleController {
|
||||
|
||||
@Autowired
|
||||
private VehicleService vehicleService;
|
||||
|
||||
@GetMapping
|
||||
public ResponseEntity<VehicleBrandDto> showVehicleBrands(){
|
||||
throw new UnsupportedOperationException();
|
||||
@RequestMapping("vehicles")
|
||||
|
||||
public ResponseEntity<List<VehicleBrandDto>> showVehicleBrands() {
|
||||
|
||||
var items = new ArrayList<VehicleBrandDto>();
|
||||
|
||||
for (var v : vehicleService.findAllBrands()
|
||||
) {
|
||||
|
||||
VehicleBrandDto dto = new VehicleBrandDto();
|
||||
dto.setName(v.getName());
|
||||
dto.setId(v.getBrandId());
|
||||
|
||||
items.add(dto);
|
||||
|
||||
}
|
||||
|
||||
|
||||
return ResponseEntity.ok(items);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
package eu.csc.ODPAppVehOwnServer.controller.registration;
|
||||
|
||||
import eu.csc.ODPAppVehOwnServer.controller.AbstractRestController;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class DeviceRegistrationController {
|
||||
@RequestMapping("reg/devices")
|
||||
public class DeviceRegistrationController extends AbstractRestController {
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
package eu.csc.ODPAppVehOwnServer.controller.registration;
|
||||
|
||||
import eu.csc.ODPAppVehOwnServer.controller.AbstractRestController;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class VehicleRegistrationController {
|
||||
@RequestMapping("reg/vehicles")
|
||||
public class VehicleRegistrationController extends AbstractRestController {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,21 @@
|
|||
package eu.csc.ODPAppVehOwnServer.web.HTTPRequestTest.controller;
|
||||
|
||||
import eu.csc.ODPAppVehOwnServer.client.clients.VehOwnAppClient;
|
||||
import eu.csc.ODPAppVehOwnServer.client.service.ClientService;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.boot.web.server.LocalServerPort;
|
||||
|
||||
public abstract class AbstractConfigControllerTester {
|
||||
@Autowired
|
||||
protected TestRestTemplate restTemplate;
|
||||
protected String url;
|
||||
|
||||
@LocalServerPort
|
||||
protected int port;
|
||||
protected VehOwnAppClient client;
|
||||
|
||||
|
||||
public void setUp(){
|
||||
|
||||
|
|
|
|||
|
|
@ -1,13 +1,22 @@
|
|||
|
||||
package eu.csc.ODPAppVehOwnServer.web.HTTPRequestTest.controller;
|
||||
import eu.csc.ODPAppVehOwnServer.ODPAppVehOwnServerApplication;
|
||||
import eu.csc.ODPAppVehOwnServer.client.ClientFactory;
|
||||
import eu.csc.ODPAppVehOwnServer.client.clients.VehOwnAppClient;
|
||||
import eu.csc.ODPAppVehOwnServer.client.service.ClientService;
|
||||
import eu.csc.ODPAppVehOwnServer.models.data.DeviceDto;
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.services.VehicleService;
|
||||
import eu.csc.data.IConfigConsts;
|
||||
import lombok.var;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @see
|
||||
|
|
@ -20,15 +29,38 @@ public class TestConfigCapabilityController
|
|||
@Autowired
|
||||
private EntityManagerFactory entityManagerFactory;
|
||||
|
||||
@Autowired
|
||||
private VehicleService vehicleService;
|
||||
|
||||
@Override
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
super.setUp();
|
||||
this.url = "http://localhost:" + port;
|
||||
this.client = ClientFactory.createVehOwnAppClient(this.url);
|
||||
|
||||
|
||||
this.url = this.url +"/api/";
|
||||
super.setUp();
|
||||
reset();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void name() {
|
||||
Assertions.assertTrue(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGet(){
|
||||
System.out.println(vehicleService.findAllBrands());
|
||||
}
|
||||
|
||||
@Test
|
||||
void tt() throws IOException {
|
||||
var rr = this.client.listDevices();
|
||||
|
||||
System.out.println("Body: " + rr);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,47 @@
|
|||
package eu.csc.ODPAppVehOwnServer.shell;
|
||||
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.services.DeviceService;
|
||||
import eu.csc.ODPAppVehOwnServer.persistence.services.VehicleService;
|
||||
import lombok.var;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.shell.standard.ShellComponent;
|
||||
import org.springframework.shell.standard.ShellMethod;
|
||||
import org.springframework.shell.standard.ShellOption;
|
||||
|
||||
@ShellComponent
|
||||
public class DeviceCommands extends BaseCommands{
|
||||
|
||||
@Autowired
|
||||
private DeviceService deviceService;
|
||||
@ShellMethod(value = "list Devices", key = {"d_l"})
|
||||
public String listVehicles(){
|
||||
|
||||
for (var vehicle:deviceService.findAll()
|
||||
) {
|
||||
addMessageString(vehicle.toString());
|
||||
}
|
||||
|
||||
return getMessageString();
|
||||
}
|
||||
|
||||
|
||||
@ShellMethod(value = "add Device", key = {"d_a", "d-a"})
|
||||
public String addDevice(String brand, String name, String manufacturer){
|
||||
addMessageString(deviceService.addDevice(brand, name,manufacturer).toString());
|
||||
|
||||
return getMessageString();
|
||||
}
|
||||
|
||||
@ShellMethod(value = "add Device", key = {"d_aa", "d-aa"})
|
||||
public String addDeviceArticle(String device, @ShellOption(defaultValue = ShellOption.NULL) String articlenumber){
|
||||
if(articlenumber != null)
|
||||
addMessageString(deviceService.generateDeviceArticle(device, articlenumber).toString());
|
||||
|
||||
else
|
||||
addMessageString(deviceService.generateDeviceArticle(device).toString());
|
||||
return getMessageString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -2,3 +2,13 @@
|
|||
1652779115434:v_l
|
||||
1652779425455:v-a a a
|
||||
1652779496144:v_l
|
||||
1652800711948:v_am ford a a
|
||||
1652800720475:v_a ford ford
|
||||
1652800728673:v_am ford a a
|
||||
1652800802689:v_l
|
||||
1653243154197:d_a a a a
|
||||
1653243160595:d_l
|
||||
1653243323125:d_aa a
|
||||
1653243329540:d_l
|
||||
1653243522085:d_aa a
|
||||
1653243633459:d_l
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package eu.csc.ODPAppVehOwnServer.client;
|
||||
|
||||
import eu.csc.ODPAppVehOwnServer.client.clients.VehOwnAppClient;
|
||||
import eu.csc.ODPAppVehOwnServer.models.JWTTokenResponse;
|
||||
import eu.csc.ODPAppVehOwnServer.models.auth.AuthenticationRequest;
|
||||
import eu.csc.odpconfigserver.client.adapter.ErrorHandlingCallAdapterFactory;
|
||||
|
|
@ -37,6 +38,8 @@ public class ClientFactory {
|
|||
|
||||
public static AuthenticationService createAuthenticationService(String url) {
|
||||
return createService(url, AuthenticationService.class);
|
||||
} public static VehOwnAppClient createVehOwnAppClient(String url) {
|
||||
return new VehOwnAppClient(url);
|
||||
}
|
||||
|
||||
public static <S> S createService(String url, Class<S> serviceClass, String user, String password) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
package eu.csc.ODPAppVehOwnServer.client.clients;
|
||||
|
||||
import eu.csc.ODPAppVehOwnServer.client.models.CallResponse;
|
||||
import eu.csc.ODPAppVehOwnServer.models.VehicleBrandDto;
|
||||
import eu.csc.ODPAppVehOwnServer.models.VehicleModelDto;
|
||||
import eu.csc.ODPAppVehOwnServer.models.data.DeviceDto;
|
||||
import eu.csc.ODPAppVehOwnServer.models.data.LanguageDto;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
@ -13,6 +15,8 @@ public interface IDataClient {
|
|||
|
||||
List<VehicleBrandDto> listVehicleBrands() throws IOException;
|
||||
|
||||
CallResponse<List<DeviceDto>> listDevices() throws IOException;
|
||||
|
||||
List<VehicleModelDto> listVehicleModels() throws IOException;
|
||||
List<VehicleModelDto> listVehicleModels(VehicleBrandDto brand) throws IOException;
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import eu.csc.ODPAppVehOwnServer.client.models.CallResponse;
|
|||
import eu.csc.ODPAppVehOwnServer.client.service.ClientService;
|
||||
import eu.csc.ODPAppVehOwnServer.models.VehicleBrandDto;
|
||||
import eu.csc.ODPAppVehOwnServer.models.VehicleModelDto;
|
||||
import eu.csc.ODPAppVehOwnServer.models.data.DeviceDto;
|
||||
import eu.csc.ODPAppVehOwnServer.models.data.LanguageDto;
|
||||
import lombok.var;
|
||||
|
||||
|
|
@ -22,6 +23,10 @@ public class VehOwnAppClient extends AbstractClient implements IDataClient {
|
|||
//region Constructors
|
||||
|
||||
|
||||
public VehOwnAppClient(String url) {
|
||||
|
||||
this.clientService = ClientFactory.createService(url, ClientService.class);
|
||||
}
|
||||
public VehOwnAppClient(String url, String token) {
|
||||
var builder = getRetrofitBuilder(url);
|
||||
var interceptor = getTokenAuthenticationInterceptor(token);
|
||||
|
|
@ -47,6 +52,11 @@ public class VehOwnAppClient extends AbstractClient implements IDataClient {
|
|||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CallResponse<List<DeviceDto>> listDevices() throws IOException {
|
||||
return executeCall(clientService.listDevices());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VehicleModelDto> listVehicleModels() throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
package eu.csc.ODPAppVehOwnServer.client.clients;
|
||||
|
||||
|
||||
import eu.csc.ODPAppVehOwnServer.client.models.CallResponse;
|
||||
import eu.csc.ODPAppVehOwnServer.client.service.ClientService;
|
||||
import eu.csc.ODPAppVehOwnServer.models.VehicleBrandDto;
|
||||
import eu.csc.ODPAppVehOwnServer.models.VehicleModelDto;
|
||||
import eu.csc.ODPAppVehOwnServer.models.data.DeviceDto;
|
||||
import eu.csc.ODPAppVehOwnServer.models.data.LanguageDto;
|
||||
import lombok.var;
|
||||
|
||||
|
|
@ -33,6 +35,7 @@ public class VehOwnAppClientDummy extends AbstractClient implements IDataClient
|
|||
|
||||
private final List<VehicleBrandDto> vehicleBrandDtos;
|
||||
private final List<VehicleModelDto> vehicleModelDtos;
|
||||
private final List<DeviceDto> devices;
|
||||
|
||||
//endregion
|
||||
|
||||
|
|
@ -84,6 +87,7 @@ public class VehOwnAppClientDummy extends AbstractClient implements IDataClient
|
|||
) {
|
||||
this.vehicleModelDtos.addAll(brand.getModels());
|
||||
}
|
||||
devices = new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -102,6 +106,11 @@ public class VehOwnAppClientDummy extends AbstractClient implements IDataClient
|
|||
return this.vehicleBrandDtos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CallResponse<List<DeviceDto>> listDevices() throws IOException {
|
||||
return new CallResponse<List<DeviceDto>>(this.devices);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VehicleModelDto> listVehicleModels() throws IOException {
|
||||
return this.vehicleModelDtos;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
package eu.csc.ODPAppVehOwnServer.client.models;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
import retrofit2.Response;
|
||||
|
||||
@Getter
|
||||
@ToString(callSuper = true)
|
||||
public class CallResponse<T> {
|
||||
|
||||
private T body;
|
||||
|
|
@ -33,6 +35,11 @@ public class CallResponse<T> {
|
|||
success = false;
|
||||
}
|
||||
|
||||
public CallResponse(T body) {
|
||||
this.body = body;
|
||||
this.success = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CallResponse{" +
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package eu.csc.ODPAppVehOwnServer.client.service;
|
|||
import eu.csc.ODPAppVehOwnServer.models.JWTTokenResponse;
|
||||
import eu.csc.ODPAppVehOwnServer.models.VehicleBrandDto;
|
||||
import eu.csc.ODPAppVehOwnServer.models.auth.AuthenticationRequest;
|
||||
import eu.csc.ODPAppVehOwnServer.models.data.DeviceDto;
|
||||
import eu.csc.ODPAppVehOwnServer.models.data.LanguageDto;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.Body;
|
||||
|
|
@ -22,5 +23,7 @@ public interface ClientService {
|
|||
|
||||
@GET("/api/vehicles/")
|
||||
Call<List<VehicleBrandDto>> listVehicleModel();
|
||||
@GET("/api/devices/")
|
||||
Call<List<DeviceDto>> listDevices();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
package eu.csc.ODPAppVehOwnServer.models.data;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
public class DeviceDto {
|
||||
private Long id;
|
||||
private String devicenumber;
|
||||
|
||||
|
||||
private String name;
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
package eu.csc.ODPAppVehOwnServer.models.data;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
public class ErrorResultDto implements Serializable {
|
||||
private String msg;
|
||||
private Integer code;
|
||||
|
||||
public ErrorResultDto(String msg){
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
|
||||
public ErrorResultDto(Integer code, String msg){
|
||||
this.msg = msg;
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public ErrorResultDto(String msg, Integer code){
|
||||
this.msg = msg;
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public static ErrorResultDto get(Exception ex) {
|
||||
return new ErrorResultDto(ex.toString());
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue