Small addition to be webapi compliant

This commit is contained in:
anthonyraymond 2018-02-07 00:06:34 +01:00
parent b610c5acb0
commit a933989eb8
12 changed files with 52 additions and 15 deletions

View file

@ -68,6 +68,9 @@ public class SeedManager {
}
public void startSeeding() throws IOException {
if (this.client != null) {
return;
}
this.configProvider.init();
final List<String> clientFiles = this.bitTorrentClientProvider.listClientFiles();
this.publisher.publishEvent(new ListOfClientFilesEvent(clientFiles));

View file

@ -1,10 +1,18 @@
package org.araymond.joal.web.config;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.module.SimpleModule;
import org.araymond.joal.core.torrent.torrent.InfoHash;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import java.io.IOException;
/**
* Created by raymo on 30/06/2017.
*/
@ -17,7 +25,20 @@ public class JacksonConfig {
.featuresToDisable(
SerializationFeature.WRITE_DATES_AS_TIMESTAMPS
)
.failOnEmptyBeans(false);
.failOnEmptyBeans(false)
.serializers(new InfoHashSerializer());
}
public static final class InfoHashSerializer extends JsonSerializer<InfoHash> {
@Override
public void serialize(final InfoHash value, final JsonGenerator gen, final SerializerProvider serializers) throws IOException, JsonProcessingException {
gen.writeString(value.value());
}
@Override
public Class<InfoHash> handledType() {
return InfoHash.class;
}
}
}

View file

@ -26,4 +26,8 @@ public class FailedToAnnouncePayload extends AnnouncePayload {
public int getInterval() {
return interval;
}
public LocalDateTime getDateTime() {
return dateTime;
}
}

View file

@ -22,4 +22,12 @@ public class SuccessfullyAnnouncePayload extends AnnouncePayload {
public int getInterval() {
return interval;
}
public RequestEvent getRequestEvent() {
return requestEvent;
}
public LocalDateTime getDateTime() {
return dateTime;
}
}

View file

@ -13,4 +13,8 @@ public class WillAnnouncePayload extends AnnouncePayload {
super(event.getInfoHash());
this.dateTime = LocalDateTime.now();
}
public LocalDateTime getDateTime() {
return dateTime;
}
}

View file

@ -8,7 +8,6 @@ import org.araymond.joal.web.messages.outgoing.MessagePayload;
* Created by raymo on 08/07/2017.
*/
public class ConfigHasBeenLoadedPayload implements MessagePayload {
private final AppConfiguration config;
public ConfigHasBeenLoadedPayload(final ConfigHasBeenLoadedEvent event) {

View file

@ -8,7 +8,6 @@ import org.araymond.joal.web.messages.outgoing.MessagePayload;
* Created by raymo on 09/07/2017.
*/
public class ConfigIsInDirtyStatePayload implements MessagePayload {
private final AppConfiguration config;
public ConfigIsInDirtyStatePayload(final ConfigurationIsInDirtyStateEvent event) {

View file

@ -7,7 +7,6 @@ import org.araymond.joal.web.messages.outgoing.MessagePayload;
* Created by raymo on 08/07/2017.
*/
public class InvalidConfigPayload implements MessagePayload {
private final String error;
public InvalidConfigPayload(final AppConfigurationIntegrityException e) {

View file

@ -9,7 +9,6 @@ import java.util.List;
* Created by raymo on 08/07/2017.
*/
public class ListOfClientFilesPayload implements MessagePayload {
private final List<String> clients;
public ListOfClientFilesPayload(final ListOfClientFilesEvent event) {

View file

@ -1,24 +1,25 @@
package org.araymond.joal.web.messages.outgoing.impl.files;
import org.araymond.joal.core.events.torrent.files.TorrentFileAddedEvent;
import org.araymond.joal.core.torrent.torrent.InfoHash;
import org.araymond.joal.web.messages.outgoing.MessagePayload;
/**
* Created by raymo on 10/07/2017.
*/
public class TorrentFileAddedPayload implements MessagePayload {
private final String id;
private final InfoHash infoHash;
private final String name;
private final Long size;
public TorrentFileAddedPayload(final TorrentFileAddedEvent event) {
this.id = event.getTorrent().getHexInfoHash();
this.infoHash = event.getTorrent().getTorrentInfoHash();
this.name = event.getTorrent().getName();
this.size = event.getTorrent().getSize();
}
public String getId() {
return id;
public InfoHash getInfoHash() {
return infoHash;
}
public String getName() {

View file

@ -1,24 +1,25 @@
package org.araymond.joal.web.messages.outgoing.impl.files;
import org.araymond.joal.core.events.torrent.files.TorrentFileDeletedEvent;
import org.araymond.joal.core.torrent.torrent.InfoHash;
import org.araymond.joal.web.messages.outgoing.MessagePayload;
/**
* Created by raymo on 10/07/2017.
*/
public class TorrentFileDeletedPayload implements MessagePayload {
private final String id;
private final InfoHash infoHash;
private final String name;
private final Long size;
public TorrentFileDeletedPayload(final TorrentFileDeletedEvent event) {
this.id = event.getTorrent().getHexInfoHash();
this.infoHash = event.getTorrent().getTorrentInfoHash();
this.name = event.getTorrent().getName();
this.size = event.getTorrent().getSize();
}
public String getId() {
return id;
public InfoHash getInfoHash() {
return infoHash;
}
public String getName() {

View file

@ -5,7 +5,6 @@ import org.araymond.joal.web.annotations.ConditionalOnWebUi;
import org.araymond.joal.web.messages.outgoing.MessagePayload;
import org.araymond.joal.web.messages.outgoing.StompMessage;
import org.araymond.joal.web.messages.outgoing.impl.announce.AnnouncePayload;
import org.araymond.joal.web.messages.outgoing.impl.announce.WillAnnouncePayload;
import org.araymond.joal.web.messages.outgoing.impl.files.TorrentFileAddedPayload;
import org.araymond.joal.web.messages.outgoing.impl.files.TorrentFileDeletedPayload;
import org.springframework.messaging.MessagingException;
@ -98,7 +97,7 @@ public class JoalMessageSendingTemplate {
return false;
}
final TorrentFileDeletedPayload newMsg = (TorrentFileDeletedPayload) stompMessage.getPayload();
return ((TorrentFileAddedPayload) message.getPayload()).getId().equals(newMsg.getId());
return ((TorrentFileAddedPayload) message.getPayload()).getInfoHash().equals(newMsg.getInfoHash());
});
break;
}