Skip to content

Commit

Permalink
Merge pull request #79 from isuru89/impl/documentation
Browse files Browse the repository at this point in the history
new admin db implementation started #76
  • Loading branch information
isuru89 authored Feb 13, 2021
2 parents 282e287 + 9239254 commit 669551e
Show file tree
Hide file tree
Showing 114 changed files with 2,769 additions and 1,802 deletions.
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
/scripts/examples
/svp
/web/node_modules
/data
/data
*.db
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ src/main/resources/io/github/isuru/oasis/db/.vscode/
*.mv.db

*.log
*.db

node_modules/

139 changes: 24 additions & 115 deletions core/src/main/java/io/github/oasis/core/elements/AbstractDef.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import io.github.oasis.core.elements.matchers.TimeRangeMatcherFactory;
import io.github.oasis.core.utils.Texts;
import io.github.oasis.core.utils.Utils;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.io.Serializable;
import java.util.Collection;
Expand All @@ -31,8 +34,16 @@
import java.util.Set;

/**
* This is the base definition for any type of element which is going to be processed
* by engine. This definition object will directly be created by reading definition
* files or parsing event object in engine.
*
* Finally this definition will be used to create a rule instance.
*
* @author Isuru Weerarathna
*/
@Getter
@Setter
public abstract class AbstractDef implements Serializable {

protected static final String EMPTY = "";
Expand All @@ -45,12 +56,19 @@ public abstract class AbstractDef implements Serializable {
private String id;
private String name;
private String description;
private String plugin;

/**
* Specify single or multiple events this rule should process on.
*/
private Object event;
private Object events;
/**
* This filter filter out events based on its data before sending it to processor.
*/
private Object eventFilter;

private Set<String> flags;
private Object condition;

private List<TimeRangeDef> timeRanges;

Expand All @@ -59,7 +77,7 @@ public static AbstractRule defToRule(AbstractDef def, AbstractRule source) {
source.setDescription(def.getDescription());
source.setFlags(Objects.isNull(def.flags) ? Set.of() : Set.copyOf(def.getFlags()));
source.setEventTypeMatcher(def.deriveEventMatcher());
source.setCondition(EventExecutionFilterFactory.create(def.condition));
source.setEventFilter(EventExecutionFilterFactory.create(def.eventFilter));
source.setTimeRangeMatcher(TimeRangeMatcherFactory.create(def.timeRanges));
return source;
}
Expand All @@ -74,142 +92,33 @@ private EventTypeMatcher deriveEventMatcher() {
return null;
}

public Object getEvent() {
return event;
}

public void setEvent(Object event) {
this.event = event;
}

protected List<String> getSensitiveAttributes() {
return List.of(
Utils.firstNonNullAsStr(event, EMPTY),
Utils.firstNonNullAsStr(events, EMPTY),
Utils.firstNonNullAsStr(flags, EMPTY),
Utils.firstNonNullAsStr(condition, EMPTY)
Utils.firstNonNullAsStr(eventFilter, EMPTY)
);
}

public final String generateUniqueHash() {
return Texts.md5Digest(String.join("", getSensitiveAttributes()));
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public Set<String> getFlags() {
return flags;
}

public void setFlags(Set<String> flags) {
this.flags = flags;
}

public Object getCondition() {
return condition;
}

public void setCondition(Object condition) {
this.condition = condition;
}

public Object getEvents() {
return events;
}

public void setEvents(Object events) {
this.events = events;
}

public List<TimeRangeDef> getTimeRanges() {
return timeRanges;
}

public void setTimeRanges(List<TimeRangeDef> timeRanges) {
this.timeRanges = timeRanges;
}

@Getter
@Setter
@NoArgsConstructor
public static class TimeRangeDef {
private String type;
private Object from;
private Object to;
private Object when;
private Object expression;

public TimeRangeDef() {
}

public TimeRangeDef(String type, Object from, Object to) {
this.type = type;
this.from = from;
this.to = to;
}

public TimeRangeDef(String type, Object when) {
this.type = type;
this.when = when;
}

public Object getExpression() {
return expression;
}

public void setExpression(Object expression) {
this.expression = expression;
}

public Object getWhen() {
return when;
}

public void setWhen(Object when) {
this.when = when;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public Object getFrom() {
return from;
}

public void setFrom(Object from) {
this.from = from;
}

public Object getTo() {
return to;
}

public void setTo(Object to) {
this.to = to;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private boolean isMatchEvent(Event event, AbstractRule rule) {
*/
private boolean canSkip(Event event, AbstractRule rule, ExecutionContext context) {
return !rule.isEventFalls(event, context)
|| !rule.isConditionMatches(event, context);
|| !rule.isEventFilterSatisfy(event, context);
}

}
71 changes: 11 additions & 60 deletions core/src/main/java/io/github/oasis/core/elements/AbstractRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,22 @@

import io.github.oasis.core.Event;
import io.github.oasis.core.context.ExecutionContext;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

/**
* Base rule entity for all element rules.
* Every new rule must inherit this.
*
* @author Isuru Weerarathna
*/
@Getter
@Setter
public abstract class AbstractRule implements Serializable {

private final String id;
Expand All @@ -38,7 +45,7 @@ public abstract class AbstractRule implements Serializable {
private Set<String> flags = new HashSet<>();
private EventTypeMatcher eventTypeMatcher;
private TimeRangeMatcher timeRangeMatcher;
private EventExecutionFilter condition;
private EventExecutionFilter eventFilter;
private boolean active = true;

public AbstractRule(String id) {
Expand All @@ -53,70 +60,14 @@ public boolean doesNotHaveFlag(String flag) {
return !flags.contains(flag);
}

public void setFlags(Set<String> flags) {
this.flags = flags;
}

public EventExecutionFilter getCondition() {
return condition;
}

public void setCondition(EventExecutionFilter condition) {
this.condition = condition;
}

public void setEventTypeMatcher(EventTypeMatcher eventTypeMatcher) {
this.eventTypeMatcher = eventTypeMatcher;
}

public EventTypeMatcher getEventTypeMatcher() {
return eventTypeMatcher;
}

public String getId() {
return id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public boolean isActive() {
return active;
}

public void setActive(boolean active) {
this.active = active;
}

public void setTimeRangeMatcher(TimeRangeMatcher timeRangeMatcher) {
this.timeRangeMatcher = timeRangeMatcher;
}

public TimeRangeMatcher getTimeRangeMatcher() {
return timeRangeMatcher;
}

public boolean isEventFalls(Event event, ExecutionContext executionContext) {
return Objects.isNull(timeRangeMatcher) ||
timeRangeMatcher.isBetween(event.getTimestamp(), event.getTimeZone());
}

public boolean isConditionMatches(Event event, ExecutionContext executionContext) {
return Objects.isNull(condition) ||
condition.matches(event, this, executionContext);
public boolean isEventFilterSatisfy(Event event, ExecutionContext executionContext) {
return Objects.isNull(eventFilter) ||
eventFilter.matches(event, this, executionContext);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import io.github.oasis.core.elements.AttributeInfo;
import io.github.oasis.core.elements.ElementDef;
import io.github.oasis.core.model.EventSource;
import io.github.oasis.core.model.PlayerObject;
import io.github.oasis.core.model.TeamObject;
import io.github.oasis.core.model.UserObject;

import java.util.List;

Expand All @@ -50,13 +50,13 @@ public interface OasisRepository {
boolean existsGame(String gameName);
List<Game> listGames();

UserObject readUser(long userId);
UserObject readUser(String email);
UserObject addUser(UserObject newUser);
boolean existsUser(String email);
boolean existsUser(long userId);
UserObject updateUser(long userId, UserObject updatedUser);
UserObject deleteUser(long userId);
PlayerObject readPlayer(long userId);
PlayerObject readPlayer(String email);
PlayerObject addPlayer(PlayerObject newUser);
boolean existsPlayer(String email);
boolean existsPlayer(long userId);
PlayerObject updatePlayer(long userId, PlayerObject updatedUser);
PlayerObject deletePlayer(long userId);

TeamObject addTeam(TeamObject teamObject);
TeamObject readTeam(int teamId);
Expand All @@ -65,10 +65,10 @@ public interface OasisRepository {
boolean existsTeam(int teamId);
PaginatedResult<TeamMetadata> searchTeam(String teamName, String offset, int maxRecords);

void removeUserFromTeam(long userId, int gameId, int teamId);
void addUserToTeam(long userId, int gameId, int teamId);
List<TeamObject> getUserTeams(long userId);
List<UserObject> getTeamUsers(int teamId);
void removePlayerFromTeam(long userId, int gameId, int teamId);
void addPlayerToTeam(long userId, int gameId, int teamId);
List<TeamObject> getPlayerTeams(long userId);
List<PlayerObject> getTeamPlayers(int teamId);

ElementDef addNewElement(int gameId, ElementDef elementDef);
ElementDef updateElement(int gameId, String id, ElementDef elementDef);
Expand Down
Loading

0 comments on commit 669551e

Please sign in to comment.