Skip to content

Commit

Permalink
Adding index creation classes
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandonogueira committed May 13, 2017
1 parent e9f31c0 commit e166a3d
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.OkraScheduler</groupId>
<artifactId>OkraApi</artifactId>
<version>1.1.1</version>
<version>1.2.0</version>

<properties>
<source.enconding>UTF-8</source.enconding>
Expand Down
60 changes: 60 additions & 0 deletions src/main/java/okra/base/AbstractOkra.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
import lombok.AccessLevel;
import lombok.Data;
import lombok.Setter;
import okra.index.IndexDefinition;
import okra.index.Ordering;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Setter(AccessLevel.NONE)
@Data
Expand All @@ -33,8 +39,62 @@ public abstract class AbstractOkra<T extends OkraItem> implements Okra<T> {
private final String database;
private final String collection;

private List<IndexDefinition> indexDefinitions;

public AbstractOkra(final String database, final String collection) {
this.collection = collection;
this.database = database;
}

@Override
public List<IndexDefinition> indexDefinitions() {
if (indexDefinitions == null) {
return generateDefaultIndexDefinitions();
}
return indexDefinitions;
}

@Override
public void setIndexDefinitions(List<IndexDefinition> indexDefinitions) {
this.indexDefinitions = indexDefinitions;
}

private List<IndexDefinition> generateDefaultIndexDefinitions() {
List<String> statusRunDate = new ArrayList<>();
statusRunDate.add("status");
statusRunDate.add("runDate");

IndexDefinition statusRunDateDef = new IndexDefinition();
statusRunDateDef.setAttrs(statusRunDate);
statusRunDateDef.setOrdering(Ordering.ASC);


List<String> statusHeartbeat = new ArrayList<>();
statusHeartbeat.add("status");
statusHeartbeat.add("heartbeat");

IndexDefinition statusHeartbeatDef = new IndexDefinition();
statusHeartbeatDef.setAttrs(statusHeartbeat);
statusHeartbeatDef.setOrdering(Ordering.ASC);

List<String> idStatusHeartbeat = new ArrayList<>();
idStatusHeartbeat.add("_id");
idStatusHeartbeat.add("status");
idStatusHeartbeat.add("heartbeat");

IndexDefinition idStatusHeartbeatDef = new IndexDefinition();
idStatusHeartbeatDef.setAttrs(idStatusHeartbeat);
idStatusHeartbeatDef.setOrdering(Ordering.ASC);

return Arrays.asList(
statusRunDateDef,
statusHeartbeatDef,
idStatusHeartbeatDef);
}

@Override
public void setup() {

}

}
21 changes: 20 additions & 1 deletion src/main/java/okra/base/Okra.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
package okra.base;

import okra.exception.OkraItemNotFoundException;
import okra.index.IndexDefinition;

import java.util.List;
import java.util.Map;
import java.util.Optional;

Expand Down Expand Up @@ -100,12 +102,29 @@ public interface Okra<T extends OkraItem> {

/**
* Count items by status.
*
* <p>
* e.g. how many items are pending? Or How many items are currently processing?
*
* @param status
* @return The count
*/
long countByStatus(OkraStatus status);

/**
* List of indexes that Okra will need.
* This list may change depending on the implementation. It may even be empty in some implementations.
*
* @return The list of indexes that Okra will need.
*/
List<IndexDefinition> indexDefinitions();

/**
* Sets index definitions
*/
void setIndexDefinitions(List<IndexDefinition> indexDefinitions);

/**
* Runs any previously needed setup or configurations
*/
void setup();
}
30 changes: 30 additions & 0 deletions src/main/java/okra/exception/InvalidOkraItemException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2017 Okra Scheduler
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/

package okra.exception;

public class InvalidOkraItemException extends OkraRuntimeException {
public InvalidOkraItemException() {
super("Invalid Okra Item");
}
}
49 changes: 49 additions & 0 deletions src/main/java/okra/index/IndexDefinition.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2017 Okra Scheduler
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/

package okra.index;

import java.util.List;

public class IndexDefinition {

private List<String> attrs;

private Ordering ordering;

public List<String> getAttrs() {
return attrs;
}

public void setAttrs(List<String> attrs) {
this.attrs = attrs;
}

public Ordering getOrdering() {
return ordering;
}

public void setOrdering(Ordering ordering) {
this.ordering = ordering;
}
}
28 changes: 28 additions & 0 deletions src/main/java/okra/index/Ordering.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2017 Okra Scheduler
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/

package okra.index;

public enum Ordering {
ASC, DESC
}

0 comments on commit e166a3d

Please sign in to comment.