Skip to content

Commit

Permalink
Adding Indexed Capabilities
Browse files Browse the repository at this point in the history
Adding Indexed Capabilities for practice keyword searching.
  • Loading branch information
danimaniarqsoft committed May 18, 2017
1 parent 812e144 commit 56f1d4d
Show file tree
Hide file tree
Showing 10 changed files with 256 additions and 50 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<!-- Joda Time -->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
Expand Down
10 changes: 0 additions & 10 deletions src/main/java/mx/infotec/dads/essence/EssenceImplApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,9 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;

@SpringBootApplication
public class EssenceImplApplication {

@Bean
public LocalValidatorFactoryBean validator() {
System.out.println("----------------------------------");
System.out.println("Running the app");
System.out.println("----------------------------------");
return null;
}
public static void main(String[] args) {
SpringApplication.run(EssenceImplApplication.class, args);
}
Expand Down
65 changes: 65 additions & 0 deletions src/main/java/mx/infotec/dads/essence/audit/Auditable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
*
* The MIT License (MIT)
* Copyright (c) 2016 Daniel Cortes Pichardo
*
* 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 mx.infotec.dads.essence.audit;

import org.joda.time.DateTime;

/**
* Auditable Interface, used into the Domain classes
*
* @author Daniel Cortes Pichardo
* @version 1.1
*/
public interface Auditable {

/**
* Returns the creation date of the entity.
*
* @return the createdDate
*/
DateTime getCreatedDate();

/**
* Sets the creation date of the entity.
*
* @param creationDate
* the creation date to set
*/
void setCreatedDate(final DateTime creationDate);

/**
* Returns the date of the last modification.
*
* @return the lastModifiedDate
*/
DateTime getLastModifiedDate();

/**
* Sets the date of the last modification.
*
* @param lastModifiedDate
* the date of the last modification to set
*/
void setLastModifiedDate(final DateTime lastModifiedDate);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@

import java.util.Collection;

import org.joda.time.DateTime;
import org.omg.essence.model.foundation.LanguageElement;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.mongodb.core.mapping.DBRef;

import mx.infotec.dads.essence.audit.Auditable;
import mx.infotec.dads.essence.model.view.SEFeatureSelection;
import mx.infotec.dads.essence.model.view.SEViewSelection;

Expand Down Expand Up @@ -70,7 +74,7 @@
* @version 1.1
* @since essence 1.1
*/
public abstract class SELanguageElement implements LanguageElement {
public abstract class SELanguageElement implements LanguageElement, Auditable {
/** The mongodb Id */
@Id
private String id;
Expand Down Expand Up @@ -123,6 +127,14 @@ public abstract class SELanguageElement implements LanguageElement {
@DBRef
protected Collection<SEPatternAssociation> patternAssociation;

/** The created Date **/
@CreatedDate
private DateTime createdDate;

/** The last modified Date **/
@LastModifiedDate
private DateTime lastModifiedDate;

@Override
public boolean isSuppressable() {
return isSuppressable;
Expand Down Expand Up @@ -221,4 +233,24 @@ public void setId(String id) {
this.id = id;
}

@Override
public DateTime getCreatedDate() {
return createdDate;
}

@Override
public void setCreatedDate(DateTime createdDate) {
this.createdDate = createdDate;
}

@Override
public DateTime getLastModifiedDate() {
return lastModifiedDate;
}

@Override
public void setLastModifiedDate(DateTime lastModifiedDate) {
this.lastModifiedDate = lastModifiedDate;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@
package mx.infotec.dads.essence.model.foundation;

import java.util.Collection;
import java.util.List;

import org.omg.essence.model.foundation.Practice;
import org.springframework.data.annotation.Version;
import org.springframework.data.mongodb.core.index.CompoundIndex;
import org.springframework.data.mongodb.core.mapping.Document;

import mx.infotec.dads.essence.search.MultiKeyIndexable;

/**
* <pre>
* <b>Description: </b>
Expand Down Expand Up @@ -134,7 +137,8 @@
* @since essence 1.1
*/
@Document(collection = "practices")
public class SEPractice extends SEElementGroup implements Practice {
@CompoundIndex(name = "practices_keyword_idx", def = "{'keyWords': 1}")
public class SEPractice extends SEElementGroup implements Practice, MultiKeyIndexable {

/**
* Rules on the consistency of a particular Practice. The format for writing
Expand Down Expand Up @@ -171,8 +175,10 @@ public class SEPractice extends SEElementGroup implements Practice {
*/
private Collection<String> result;

@Version
private Long version;
/**
* Keywords used for search by areas
*/
private List<String> keyWords;

@Override
public String getConsistencyRules() {
Expand Down Expand Up @@ -219,11 +225,12 @@ public void setResult(Collection<String> result) {
this.result = result;
}

public Long getVersion() {
return version;
@Override
public List<String> getKeyWords() {
return keyWords;
}

public void setVersion(Long version) {
this.version = version;
public void setKeyWords(List<String> keyWords) {
this.keyWords = keyWords;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
*/
package mx.infotec.dads.essence.repository;


import java.util.List;

import org.springframework.data.mongodb.repository.MongoRepository;

import mx.infotec.dads.essence.model.foundation.SEPractice;
Expand All @@ -35,4 +38,17 @@
*/
public interface SEPracticeRepository extends MongoRepository<SEPractice, String> {

/**
*
* @param name
* @return
*/
List<SEPractice> findByName(String name);

/**
*
* @param keyWords
* @return
*/
List<SEPractice> findByKeyWordsIn(List<String> keyWords);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
*
* The MIT License (MIT)
* Copyright (c) 2016 Daniel Cortes Pichardo
*
* 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 mx.infotec.dads.essence.search;

import java.util.List;

/**
* MultiKeyIndexable used to search for keywords
*
* @author Daniel Cortes Pichardo
* @since essence 1.1
* @version 1.1
*/
public interface MultiKeyIndexable {

List<String> getKeyWords();
}
11 changes: 9 additions & 2 deletions src/main/java/mx/infotec/dads/essence/util/EssenceMapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@

import java.util.ArrayList;

import org.joda.time.DateTime;

import mx.infotec.dads.essence.audit.Auditable;
import mx.infotec.dads.essence.model.SEGraphicalElement;
import mx.infotec.dads.essence.model.alphaandworkproduct.SEState;
import mx.infotec.dads.essence.model.foundation.SEBasicElement;
Expand Down Expand Up @@ -82,7 +85,7 @@ public static void fillPractice(SEPractice practice) {
practice.setResult(new ArrayList<>());
}

public static void fillCheckpoint(SECheckpoint checkpoint, SEState state){
public static void fillCheckpoint(SECheckpoint checkpoint, SEState state) {
fillSELanguageElements(checkpoint);
checkpoint.setName("");
checkpoint.setDescription("");
Expand All @@ -91,5 +94,9 @@ public static void fillCheckpoint(SECheckpoint checkpoint, SEState state){
checkpoint.setLevel(null);
checkpoint.setCompetencyLevel(null);
}


public static void fillBitacoraData(Auditable auditable) {
auditable.setLastModifiedDate(new DateTime());
auditable.setCreatedDate(new DateTime());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
*/
package mx.infotec.dads.essence.repository;

import java.util.List;

import org.joda.time.DateTime;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
Expand Down Expand Up @@ -56,26 +59,38 @@ public class KernelRepositoryTest {
@Test
public void insertKernel() throws Exception {
LOGGER.info("insert practice");
List<SEKernel> kernelList = kernelRepository.findAll();
SEKernel kernel = new SEKernel();
kernel.setBriefDescription("Essence default kernel");
kernel.setConsistencyRules("Consistencies rules");
kernel.setDescription("Essence default kernel");
kernel.setExtension(null);
kernel.setFeatureSelection(null);
kernel.setIcon(null);
kernel.setMergeResolution(null);
kernel.setName("essence-core");
kernel.setOwnedElements(null);// por defecto no hay elementos
kernel.setOwner(null);
kernel.setPatternAssociation(null);
kernel.setProperties(null);
kernel.setReferredElements(null);
kernel.setReferrer(null);
kernel.setReferringMethod(null);
kernel.setResource(null);
kernel.setSuppressable(false);
kernel.setTag(null);
kernel.setViewSelection(null);
if (kernelList.isEmpty()) {
kernel.setBriefDescription("Essence default kernel");
kernel.setConsistencyRules("Consistencies rules");
kernel.setDescription("Essence default kernel");
kernel.setExtension(null);
kernel.setFeatureSelection(null);
kernel.setIcon(null);
kernel.setMergeResolution(null);
kernel.setName("essence-core");
kernel.setOwnedElements(null);// por defecto no hay elementos
kernel.setOwner(null);
kernel.setPatternAssociation(null);
kernel.setProperties(null);
kernel.setReferredElements(null);
kernel.setReferrer(null);
kernel.setReferringMethod(null);
kernel.setResource(null);
kernel.setSuppressable(false);
kernel.setTag(null);
kernel.setViewSelection(null);
kernel.setCreatedDate(new DateTime());
kernel.setLastModifiedDate(new DateTime());

} else {
kernel = kernelList.get(0);
kernel.setName("otro nombre");
kernel.setCreatedDate(new DateTime());
kernel.setLastModifiedDate(new DateTime());
}

kernelRepository.save(kernel);
id = kernel.getId();
LOGGER.info("id = {}", id);
Expand Down
Loading

0 comments on commit 56f1d4d

Please sign in to comment.