Skip to content

Commit

Permalink
Bumps dependency (to snapshot, and updates codebase for new api)
Browse files Browse the repository at this point in the history
  • Loading branch information
quasarchimaere committed Feb 7, 2020
1 parent ee761fc commit cfb29ec
Show file tree
Hide file tree
Showing 14 changed files with 285 additions and 444 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<dependency>
<groupId>at.researchstudio.sat</groupId>
<artifactId>won-bot</artifactId>
<version>0.8</version>
<version>0.9-SNAPSHOT</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@
import won.protocol.util.linkeddata.WonLinkedDataUtils;

/**
* BaseEventBotAction connecting two atoms on the specified sockets or on two
* other, compatible sockets. Requires an AtomSpecificEvent to run and expeects
* the atomURI from the event to be associated with another atom URI via the
* BaseEventBotAction connecting two atoms on the specified sockets or on two other, compatible sockets. Requires an
* AtomSpecificEvent to run and expeects the atomURI from the event to be associated with another atom URI via the
* botContext.saveToObjectMap method.
*/
public class ConnectWithAssociatedAtomAction extends BaseEventBotAction {
Expand All @@ -47,7 +46,7 @@ public class ConnectWithAssociatedAtomAction extends BaseEventBotAction {
private final String welcomeMessage;

public ConnectWithAssociatedAtomAction(final EventListenerContext eventListenerContext, final URI targetSocketType,
final URI localSocketType, String welcomeMessage) {
final URI localSocketType, String welcomeMessage) {
super(eventListenerContext);
Objects.requireNonNull(targetSocketType);
Objects.requireNonNull(localSocketType);
Expand All @@ -56,11 +55,6 @@ public ConnectWithAssociatedAtomAction(final EventListenerContext eventListenerC
this.welcomeMessage = welcomeMessage;
}

public ConnectWithAssociatedAtomAction(EventListenerContext eventListenerContext, String welcomeMessage) {
super(eventListenerContext);
this.welcomeMessage = welcomeMessage;
}

@Override
public void doRun(Event event, EventListener executingListener) {
if (!(event instanceof AtomSpecificEvent)) {
Expand All @@ -85,39 +79,26 @@ private Optional<WonMessage> createWonMessage(URI fromUri, URI toUri) throws Won
LinkedDataSource linkedDataSource = getEventListenerContext().getLinkedDataSource();
if (localSocketType.isPresent() && targetSocketType.isPresent()) {
URI localSocket = localSocketType
.map(socketType -> WonLinkedDataUtils
.getSocketsOfType(fromUri, socketType, linkedDataSource)
.stream().findFirst())
.orElseThrow(() -> new IllegalStateException("No socket found to connect on " + fromUri))
.get();
.map(socketType -> WonLinkedDataUtils.getSocketsOfType(fromUri, socketType, linkedDataSource)
.stream().findFirst())
.orElseThrow(() -> new IllegalStateException("No socket found to connect on " + fromUri)).get();
URI targetSocket = targetSocketType
.map(socketType -> WonLinkedDataUtils.getSocketsOfType(toUri, socketType, linkedDataSource)
.stream()
.findFirst())
.orElseThrow(() -> new IllegalStateException("No socket found to connect on " + fromUri))
.get();
return Optional.of(WonMessageBuilder
.connect()
.sockets()
/**/.sender(localSocket)
/**/.recipient(targetSocket)
.content().text(welcomeMessage).build());
.map(socketType -> WonLinkedDataUtils.getSocketsOfType(toUri, socketType, linkedDataSource).stream()
.findFirst())
.orElseThrow(() -> new IllegalStateException("No socket found to connect on " + fromUri)).get();
return Optional.of(WonMessageBuilder.connect().sockets()/**/.sender(localSocket)/**/.recipient(targetSocket)
.content().text(welcomeMessage).build());
}
// no sockets specified or specified sockets not supported. try a random
// compatibly pair
Set<Pair<URI>> compatibleSockets = WonLinkedDataUtils.getCompatibleSocketsForAtoms(linkedDataSource, fromUri,
toUri);
toUri);
if (!compatibleSockets.isEmpty()) {
List<Pair<URI>> shuffledSocketPairs = new ArrayList<>(compatibleSockets);
Collections.shuffle(shuffledSocketPairs);
Pair<URI> sockets = shuffledSocketPairs.get(0);
return Optional.of(WonMessageBuilder
.connect()
.sockets()
/**/.sender(sockets.getFirst())
/**/.recipient(sockets.getSecond())
.content().text(welcomeMessage)
.build());
return Optional.of(WonMessageBuilder.connect().sockets()/**/.sender(sockets.getFirst())
/**/.recipient(sockets.getSecond()).content().text(welcomeMessage).build());
}
return Optional.empty();
}
Expand Down
Loading

0 comments on commit cfb29ec

Please sign in to comment.