Fix file storage

master
esensar 2018-09-13 00:15:59 +02:00
parent 91d02f798e
commit 8dc317396e
8 changed files with 93 additions and 10 deletions

View File

@ -46,7 +46,7 @@ public class FileSystemStorageService implements StorageService {
String tempDest="";
String[] locations=this.rootLocation.resolve(dest).toString().split("/");
for(int i=0; i<locations.length-1;i++)
tempDest=tempDest+"/"+locations[i];
tempDest=tempDest+locations[i]+"/";
if(!Files.exists(Paths.get(tempDest)))
Files.createDirectory(Paths.get(tempDest));

2
config

@ -1 +1 @@
Subproject commit f7492aa6e9e3b1ec809e1088d2b6a3785657970f
Subproject commit dbff79cfd99b1937b676ef10efc1443e2620a92e

View File

@ -2,7 +2,10 @@ package ba.steleks.controller;
import ba.steleks.error.exception.ExternalServiceException;
import ba.steleks.model.Event;
import ba.steleks.model.EventRequest;
import ba.steleks.model.Media;
import ba.steleks.repository.EventsJpaRepository;
import ba.steleks.repository.MediaJpaRepository;
import ba.steleks.util.ProxyHeaders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.rest.webmvc.RepositoryRestController;
@ -13,6 +16,8 @@ import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
import java.net.URI;
import java.util.HashSet;
import java.util.Set;
/**
* Created by admin on 01/04/2017.
@ -22,17 +27,32 @@ import java.net.URI;
public class EventController {
private EventsJpaRepository repository;
private MediaJpaRepository mediaJpaRepository;
@Autowired
public EventController(EventsJpaRepository repository) {
public EventController(EventsJpaRepository repository, MediaJpaRepository mediaJpaRepository) {
this.repository = repository;
this.mediaJpaRepository = mediaJpaRepository;
}
@RequestMapping(path = "/events", method = RequestMethod.POST)
public ResponseEntity<?> add(@RequestBody Event event, @RequestHeader(ProxyHeaders.USER_ID) String userId) throws ExternalServiceException {
public ResponseEntity<?> add(@RequestBody EventRequest eventRequest, @RequestHeader(ProxyHeaders.USER_ID) String userId) throws ExternalServiceException {
System.out.println(eventRequest);
try {
Event event = new Event();
event.setTitle(eventRequest.getTitle());
event.setShortText(eventRequest.getShortText());
event.setLongText(eventRequest.getLongText());
event.setCreatedById(Long.parseLong(userId));
Set<Media> savedMedia = new HashSet<>();
for (Media media : eventRequest.getMedias()) {
Media loadedMedia = mediaJpaRepository.findOne(media.getId());
savedMedia.add(loadedMedia);
System.out.println("Loaded media: " + loadedMedia);
}
Event result = repository.save(event);
result.setMediaSet(savedMedia);
result = repository.save(result);
URI location = ServletUriComponentsBuilder
.fromCurrentRequest().path("/{id}")
.buildAndExpand(result.getId()).toUri();

View File

@ -42,7 +42,7 @@ public class MediaController {
try {
BufferedImage mediaImage = null;
if (!TextUtils.isEmpty(media.getContentUrl())) {
mediaImage = ImageIO.read(new URL(media.getContentUrl()));
mediaImage = ImageIO.read(new URL(media.getContentUrl()).openStream());
}
media.setCreatedById(Long.parseLong(userId));
Media result = repository.save(media);

View File

@ -30,12 +30,12 @@ public class Event {
@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinTable(
name = "event_media_set",
joinColumns=@JoinColumn(name = "event_id"),
inverseJoinColumns = @JoinColumn(name="media_set_id")
joinColumns=@JoinColumn(name = "event_id", referencedColumnName = "id"),
inverseJoinColumns = @JoinColumn(name="media_set_id", referencedColumnName = "id")
)
private Set<Media> mediaSet;
protected Event() {}
public Event() {}
public long getId() {
return id;

View File

@ -0,0 +1,53 @@
package ba.steleks.model;
import java.util.List;
public class EventRequest {
private String title;
private String shortText;
private String longText;
private List<Media> medias;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getShortText() {
return shortText;
}
public void setShortText(String shortText) {
this.shortText = shortText;
}
public String getLongText() {
return longText;
}
public void setLongText(String longText) {
this.longText = longText;
}
public List<Media> getMedias() {
return medias;
}
public void setMedias(List<Media> medias) {
this.medias = medias;
}
@Override
public String toString() {
return "EventRequest{" +
"title='" + title + '\'' +
", shortText='" + shortText + '\'' +
", longText='" + longText + '\'' +
", medias=" + medias +
'}';
}
}

View File

@ -63,4 +63,14 @@ public class Media {
protected void onCreate() {
this.creationDate = new Timestamp(new Date().getTime());
}
@Override
public String toString() {
return "Media{" +
"id=" + id +
", contentUrl='" + contentUrl + '\'' +
", creationDate=" + creationDate +
", createdById=" + createdById +
'}';
}
}

View File

@ -1,6 +1,6 @@
#Tue Mar 28 22:00:42 CEST 2017
#Sun Sep 09 23:15:29 CEST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip