Skip to content

Commit

Permalink
Merge branch 'feat_update_0.6' into fix__403_when_accessing_own_messages
Browse files Browse the repository at this point in the history
  • Loading branch information
quasarchimaere authored Oct 14, 2019
2 parents 8793810 + 318a802 commit 492678d
Show file tree
Hide file tree
Showing 20 changed files with 351 additions and 396 deletions.
6 changes: 5 additions & 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.6-SNAPSHOT</version>
<version>0.6</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -73,6 +73,10 @@
</dependencies>
<build>
<plugins>
<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/won/bot/debugbot/DebugBotApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static void main(String[] args) {
System.exit(1);
}

//SpringApplication app = new SpringApplication("classpath:/spring/app/botApp.xml");
// SpringApplication app = new SpringApplication("classpath:/spring/app/botApp.xml");
SpringApplication app = new SpringApplication(DebugBotApp.class);
app.setWebEnvironment(false);
app.run(args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
import won.protocol.util.WonRdfUtils;

/**
* Expects a MessageToElizaEvent, passes the message to a Eliza instance and
* sends eliza's response over the connection.
* Expects a MessageToElizaEvent, passes the message to a Eliza instance and sends eliza's response over the connection.
*/
public class AnswerWithElizaAction extends BaseEventBotAction {
// use only one eliza instance for all connections
Expand All @@ -42,7 +41,7 @@ protected void doRun(final Event event, EventListener executingListener) throws
}
Model messageModel = WonRdfUtils.MessageUtils.textMessage(elizaResponse);
getEventListenerContext().getEventBus()
.publish(new ConnectionMessageCommandEvent(messageToElizaEvent.getCon(), messageModel));
.publish(new ConnectionMessageCommandEvent(messageToElizaEvent.getCon(), messageModel));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@
import java.util.*;

/**
* 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 @@ -44,7 +43,7 @@ public class ConnectWithAssociatedAtomAction extends BaseEventBotAction {
private 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 Down Expand Up @@ -87,31 +86,27 @@ private Optional<WonMessage> createWonMessage(URI fromUri, URI toUri) throws Won
LinkedDataSource linkedDataSource = getEventListenerContext().getLinkedDataSource();
if (localSocketType.isPresent() && targetSocketType.isPresent()) {
Optional<URI> localSocket = localSocketType.map(socketType -> WonLinkedDataUtils
.getSocketsOfType(fromUri, socketType, linkedDataSource).stream().findFirst().orElse(null));
.getSocketsOfType(fromUri, socketType, linkedDataSource).stream().findFirst().orElse(null));
Optional<URI> targetSocket = targetSocketType.map(socketType -> WonLinkedDataUtils
.getSocketsOfType(toUri, socketType, linkedDataSource).stream().findFirst().orElse(null));
.getSocketsOfType(toUri, socketType, linkedDataSource).stream().findFirst().orElse(null));
if (localSocket.isPresent() && targetSocket.isPresent()) {
return Optional.of(WonMessageBuilder
.setMessagePropertiesForConnect(
wonNodeInformationService.generateEventURI(localWonNode),
localSocket, fromUri, localWonNode, targetSocket, toUri, remoteWonNode,
welcomeMessage)
.build());
.setMessagePropertiesForConnect(wonNodeInformationService.generateEventURI(localWonNode),
localSocket, fromUri, localWonNode, targetSocket, toUri, remoteWonNode, 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.setMessagePropertiesForConnect(
wonNodeInformationService.generateEventURI(localWonNode), Optional.of(sockets.getFirst()),
fromUri,
localWonNode, Optional.of(sockets.getSecond()), toUri, remoteWonNode, welcomeMessage)
.build());
wonNodeInformationService.generateEventURI(localWonNode), Optional.of(sockets.getFirst()), fromUri,
localWonNode, Optional.of(sockets.getSecond()), toUri, remoteWonNode, welcomeMessage).build());
}
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@
import won.protocol.vocabulary.WONMATCH;

/**
* Creates an atom with the specified sockets. If no socket is specified, the
* chatSocket will be used.
* Creates an atom with the specified sockets. If no socket is specified, the chatSocket will be used.
*/
public class CreateDebugAtomWithSocketsAction extends AbstractCreateAtomAction {
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
Expand All @@ -54,9 +53,9 @@ public class CreateDebugAtomWithSocketsAction extends AbstractCreateAtomAction {
private boolean isInitialForConnect;

public CreateDebugAtomWithSocketsAction(final EventListenerContext eventListenerContext,
final boolean usedForTesting, final boolean doNotMatch, final URI... sockets) {
final boolean usedForTesting, final boolean doNotMatch, final URI... sockets) {
super(eventListenerContext, eventListenerContext.getBotContextWrapper().getAtomCreateListName(), usedForTesting,
doNotMatch, sockets);
doNotMatch, sockets);
}

@Override
Expand Down Expand Up @@ -119,9 +118,9 @@ protected void doRun(Event event, EventListener executingListener) throws Except
final Dataset debugAtomDataset = atomModelWrapper.copyDatasetWithoutSysinfo();
final Event origEvent = event;
logger.debug("creating atom on won node {} with content {} ", wonNodeUri,
StringUtils.abbreviate(RdfUtils.toString(debugAtomDataset), 150));
StringUtils.abbreviate(RdfUtils.toString(debugAtomDataset), 150));
WonMessage createAtomMessage = createWonMessage(wonNodeInformationService, atomURI, wonNodeUri,
debugAtomDataset);
debugAtomDataset);
// remember the atom URI so we can react to success/failure responses
EventBotActionUtils.rememberInList(ctx, atomURI, uriListName);
EventListener successCallback = event12 -> {
Expand All @@ -132,13 +131,11 @@ protected void doRun(Event event, EventListener executingListener) throws Except
HintType hintType = HintType.RANDOM_SOCKET_HINT; // default: hint to random compatible sockets
if (origEvent instanceof HintDebugCommandEvent) {
hintType = ((HintDebugCommandEvent) origEvent).getHintType();
bus.publish(new AtomCreatedEventForDebugHint(origEvent, atomURI, wonNodeUri,
debugAtomDataset,
hintType));
bus.publish(new AtomCreatedEventForDebugHint(origEvent, atomURI, wonNodeUri, debugAtomDataset,
hintType));
} else {
bus.publish(new AtomCreatedEventForDebugHint(origEvent, atomURI, wonNodeUri,
debugAtomDataset,
hintType));
bus.publish(new AtomCreatedEventForDebugHint(origEvent, atomURI, wonNodeUri, debugAtomDataset,
hintType));
}
} else if ((origEvent instanceof ConnectDebugCommandEvent) || isInitialForConnect) {
bus.publish(new AtomCreatedEventForDebugConnect(atomURI, wonNodeUri, debugAtomDataset, null));
Expand All @@ -148,9 +145,9 @@ protected void doRun(Event event, EventListener executingListener) throws Except
};
EventListener failureCallback = event1 -> {
String textMessage = WonRdfUtils.MessageUtils
.getTextMessage(((FailureResponseEvent) event1).getFailureMessage());
logger.debug("atom creation failed for atom URI {}, original message URI {}: {}", new Object[] {
atomURI, ((FailureResponseEvent) event1).getOriginalMessageURI(), textMessage });
.getTextMessage(((FailureResponseEvent) event1).getFailureMessage());
logger.debug("atom creation failed for atom URI {}, original message URI {}: {}",
new Object[] { atomURI, ((FailureResponseEvent) event1).getOriginalMessageURI(), textMessage });
EventBotActionUtils.removeFromList(ctx, atomURI, uriListName);
bus.publish(new AtomCreationFailedEvent(wonNodeUri));
};
Expand Down
Loading

0 comments on commit 492678d

Please sign in to comment.