.gitignore update

This commit is contained in:
yannick.blanken@csc-online.eu 2022-06-01 18:50:59 +02:00
parent b34800881e
commit 7a32926395
10 changed files with 82 additions and 5 deletions

View File

@ -3,6 +3,7 @@ package eu.csc.ODPAppVehOwnServer.persistence.services;
import org.springframework.core.io.Resource;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.nio.file.Path;
import java.util.stream.Stream;
@ -21,4 +22,5 @@ public interface StorageService {
void deleteAll();
void storeImage(byte[] bytes, String filename) throws IOException;
}

View File

@ -1,5 +1,6 @@
package eu.csc.ODPAppVehOwnServer.persistence.services.storage;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
@ -127,7 +128,22 @@ public class FileSystemStorageService implements StorageService {
FileSystemUtils.deleteRecursively(rootLocation.toFile());
}
@Override
@Override
public void storeImage(byte[] bytes, String filename) throws IOException {
Path destinationFile = this.rootLocation.resolve("images").resolve(
filename)
.normalize().toAbsolutePath();
logger.info(destinationFile.toString());
FileOutputStream outputStream = new FileOutputStream(destinationFile.toFile());
outputStream.write(bytes);
outputStream.close();
}
@Override
public void init() {
try {
Files.createDirectories(rootLocation);

BIN
doc/data/images/hyundai.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

View File

@ -16,4 +16,8 @@
<maven.compiler.target>15</maven.compiler.target>
</properties>
<dependencies>
</dependencies>
</project>

View File

@ -26,6 +26,9 @@ public class VehicleBrandEntity extends AbstractEntity {
@Column(nullable = false)
private String name;
@Column(nullable = true)
private String imageName;
@OneToMany(fetch = FetchType.EAGER, mappedBy = "brand", cascade = CascadeType.ALL)
private List<VehicleModelEntity> modelEntities;

View File

@ -5,10 +5,16 @@ import com.google.gson.GsonBuilder;
import org.springframework.stereotype.Service;
import java.util.Calendar;
import java.util.Optional;
@Service
public class UtilsService {
public Optional<String> getExtensionByStringHandling(String filename) {
return Optional.ofNullable(filename)
.filter(f -> f.contains("."))
.map(f -> f.substring(filename.lastIndexOf(".") + 1));
}
public String getSerialnumber (int size) {

View File

@ -6,9 +6,11 @@ import eu.csc.ODPAppVehOwnServer.persistence.entity.data.VehicleModelEntity;
import eu.csc.ODPAppVehOwnServer.persistence.respository.PropulsionTypeRepository;
import eu.csc.ODPAppVehOwnServer.persistence.respository.VehicleBrandRepository;
import eu.csc.ODPAppVehOwnServer.persistence.respository.VehicleModelRepository;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.persistence.EntityNotFoundException;
import java.util.List;
@Service
@ -23,6 +25,9 @@ public class VehicleService {
@Autowired
private PropulsionTypeRepository propulsionTypeRepository;
public List<VehicleBrandEntity> findAllBrands(){
return vehicleBrandRepository.findAll();
}
@ -79,4 +84,21 @@ public class VehicleService {
return addVehicle(brandId, name);
}
@SneakyThrows
public String setBrandImage(String brandId, String fileExtension) {
var brand = vehicleBrandRepository.findOneByBrandId(brandId);
if(!brand.isPresent())
throw new EntityNotFoundException();
brand.get().setImageName(brandId + "." + fileExtension);
vehicleBrandRepository.save(brand.get());
return brand.get().getImageName();
}
}

View File

@ -1,4 +1,4 @@
spring.profiles.active=ybdev
spring.profiles.active=@profiles.active@
spring.datasource.username=@mysql.user@
spring.datasource.password=@mysql.password@

View File

@ -14,11 +14,11 @@ public class DeviceCommands extends BaseCommands {
private DeviceService deviceService;
@ShellMethod(value = "list Devices", key = {"d_l"})
public String listVehicles() {
public String listDevices() {
for (var vehicle : deviceService.findAll()
for (var item : deviceService.findAll()
) {
addMessageString(vehicle.toString());
addMessageString(item.toString());
}
return getMessageString();

View File

@ -1,12 +1,18 @@
package eu.csc.ODPAppVehOwnServer.shell;
import eu.csc.ODPAppVehOwnServer.persistence.services.GsonService;
import eu.csc.ODPAppVehOwnServer.persistence.services.StorageService;
import eu.csc.ODPAppVehOwnServer.persistence.services.UtilsService;
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 java.io.File;
import java.io.IOException;
import java.nio.file.Files;
@ShellComponent
public class VehicleCommands extends BaseCommands {
@ -15,6 +21,11 @@ public class VehicleCommands extends BaseCommands {
@Autowired
private GsonService gsonService;
@Autowired
private UtilsService utilsService;
@Autowired
private StorageService storageService;
@ShellMethod(value = "list Vehicle", key = {"v_l", "v-l"})
public String listVehicles() {
@ -36,6 +47,19 @@ public class VehicleCommands extends BaseCommands {
}
@ShellMethod(value = "add Vehicle", key = {"v_brand_image", "v-brand-image"})
public String addVehicleImage(String brandId, String fileLocation) throws IOException {
var file = new File(fileLocation);
String filename = vehicleService.setBrandImage(brandId, utilsService.getExtensionByStringHandling(file.getName()).get());
storageService.storeImage(Files.readAllBytes(file.toPath()), filename);
return getMessageString();
}
@ShellMethod(value = "add Vehicle Model", key = {"v_am", "v-am"})
public String addVehicle(String brand, String model, String name) {
addMessageString(vehicleService.addVehicleModel(brand, model, name).toString());