Skip to content

Commit

Permalink
Merge pull request #198 from justinhrobbins/feature_194
Browse files Browse the repository at this point in the history
Feature 194
  • Loading branch information
justinhrobbins committed Dec 27, 2015
2 parents 90242ff + b55f582 commit b674457
Show file tree
Hide file tree
Showing 180 changed files with 2,766 additions and 725 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.util.List;
import java.util.Set;

public interface FlashcardFacade extends GenericCrudFacade<FlashCardDto, String>
public interface FlashcardFacade extends GenericCrudFacade<FlashCardDto, Long>
{
List<FlashCardDto> findByTagsIn(final Set<TagDto> tags) throws FlashcardsException;
List<FlashCardDto> findByTagsIn(final Set<TagDto> tags, final PageRequest page)
Expand All @@ -19,5 +19,5 @@ List<FlashCardDto> findByTagsIn(final Set<TagDto> tags, final PageRequest page)
List<FlashCardDto> findByQuestionLike(final String question, final PageRequest page)
throws FlashcardsException;
FlashCardDto findByQuestion(final String question) throws FlashcardsException;
List<FlashCardDto> findFlashcardsForTag(final String tagId, final Set<String> fields) throws FlashcardsException;
List<FlashCardDto> findFlashcardsForTag(final Long tagId, final Set<String> fields) throws FlashcardsException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import java.util.List;
import java.util.Set;

public interface TagFacade extends GenericCrudFacade<TagDto, String> {
public interface TagFacade extends GenericCrudFacade<TagDto, Long> {

TagDto findByName(final String name) throws FlashcardsException;
List<TagDto> findTagsForFlashcard(final String flashcardId, final Set<String> fields) throws FlashcardsException;
List<TagDto> findTagsForFlashcard(final Long flashcardId, final Set<String> fields) throws FlashcardsException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.robbins.flashcards.exceptions.FlashcardsException;
import org.robbins.flashcards.facade.base.GenericCrudFacade;

public interface UserFacade extends GenericCrudFacade<UserDto, String> {
public interface UserFacade extends GenericCrudFacade<UserDto, Long> {

UserDto findUserByOpenid(String openid) throws FlashcardsException;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

package org.robbins.flashcards.facade.base;

import org.robbins.flashcards.dto.BatchLoadingReceiptDto;
import org.robbins.flashcards.exceptions.FlashcardsException;

import java.util.List;
Expand All @@ -17,7 +18,7 @@ List<D> list(Integer page, Integer size, String sort, String direction,
D findOne(final ID id) throws FlashcardsException;
D findOne(final ID id, Set<String> fields) throws FlashcardsException;
D save(final D entity) throws FlashcardsException;
void save(final List<D> entities) throws FlashcardsException;
BatchLoadingReceiptDto save(final List<D> entities) throws FlashcardsException;
void delete(final ID id);
List<D> findByCreatedBy(final ID userId, final Set<String> fields) throws FlashcardsException;
}
34 changes: 34 additions & 0 deletions FlashCards_Akka/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.robbins.flashcards</groupId>
<artifactId>FlashCards_App</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>FlashCards_Akka</artifactId>
<name>FlashCards_Akka</name>
<properties>
<skip.coveralls>true</skip.coveralls>
<skip.cobertura>true</skip.cobertura>
</properties>
<scm>
<connection>scm:git:git@github.com:justinhrobbins/FlashCards_App.git</connection>
<url>scm:git:git@github.com:justinhrobbins/FlashCards_App.git</url>
<developerConnection>scm:git:git@github.com:justinhrobbins/FlashCards_App.git</developerConnection>
</scm>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>

<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-actor_2.10</artifactId>
</dependency>
</dependencies>
<build>
<finalName>FlashCards_Akka</finalName>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.robbins.load.tester;
package org.robbins.flashcards.akka;


import akka.actor.ActorSystem;
Expand All @@ -8,8 +8,6 @@
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import static org.robbins.load.tester.SpringExtension.SpringExtProvider;

/**
* The application configuration.
*/
Expand All @@ -28,7 +26,7 @@ public class AppConfiguration {
public ActorSystem actorSystem() {
ActorSystem system = ActorSystem.create("AkkaJavaSpring");
// initialize the application context in the Akka Spring Extension
SpringExtProvider.get(system).initialize(applicationContext);
SpringExtension.SpringExtProvider.get(system).initialize(applicationContext);
return system;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.robbins.load.tester;
package org.robbins.flashcards.akka;

import akka.actor.Actor;
import akka.actor.IndirectActorProducer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.robbins.load.tester;
package org.robbins.flashcards.akka;

import akka.actor.AbstractExtensionId;
import akka.actor.ExtendedActorSystem;
Expand Down
8 changes: 8 additions & 0 deletions FlashCards_Akka/src/main/resources/applicatonContext-akka.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

<bean class="org.robbins.flashcards.akka.AppConfiguration"/>

</beans>
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package org.robbins.flashcards.client;

import java.util.*;

import org.robbins.flashcards.dto.AbstractPersistableDto;
import org.robbins.flashcards.dto.TagDto;
import org.robbins.flashcards.dto.BatchLoadingReceiptDto;
import org.robbins.flashcards.exceptions.FlashcardsException;
import org.robbins.flashcards.exceptions.ServiceException;
import org.springframework.http.HttpEntity;
Expand All @@ -12,9 +10,9 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.HttpClientErrorException;

public abstract class AbstractCrudClient<E extends AbstractPersistableDto, ID> extends AbstractClient implements GenericRestCrudFacade<E, ID> {
import java.util.*;

public static final String BULK = "bulk/";
public abstract class AbstractCrudClient<E extends AbstractPersistableDto, ID> extends AbstractClient implements GenericRestCrudFacade<E, ID> {

/**
* Gets the entity list url.
Expand Down Expand Up @@ -42,7 +40,7 @@ public abstract class AbstractCrudClient<E extends AbstractPersistableDto, ID> e
*
* @return the string
*/
public abstract String postBulkEntitiesUrl();
public abstract String postBatchEntitiesUrl();

/**
* Put entity url.
Expand Down Expand Up @@ -149,8 +147,7 @@ public E save(final E entity) throws ServiceException {
final HttpEntity httpEntity = new HttpEntity(entity, getAuthHeaders());

try {
E result = getRestTemplate().postForObject(postEntityUrl(), httpEntity, getClazz());
return result;
return getRestTemplate().postForObject(postEntityUrl(), httpEntity, getClazz());
}
catch (HttpClientErrorException e) {
throw new ServiceException("Unble to save '" + entity.getClass().getSimpleName() + "' " + e.getMessage());
Expand All @@ -161,17 +158,16 @@ public E save(final E entity) throws ServiceException {
}

@Override
public void save(List<E> entities) throws FlashcardsException {
public BatchLoadingReceiptDto save(List<E> entities) throws FlashcardsException {
// set the Authentication header
@SuppressWarnings({ "unchecked", "rawtypes" })
final HttpEntity httpEntity = new HttpEntity(entities, getAuthHeaders());

try {
getRestTemplate().exchange(postBulkEntitiesUrl(), HttpMethod.POST,
httpEntity, ResponseEntity.class);
return getRestTemplate().postForObject(postBatchEntitiesUrl(), httpEntity, BatchLoadingReceiptDto.class);
}
catch (HttpClientErrorException e) {
throw new ServiceException("Unble to save '" + entities.getClass().getSimpleName() + "' " + e.getMessage());
throw new ServiceException("Unable to save '" + entities.getClass().getSimpleName() + "' " + e.getMessage());
}
catch (Exception e) {
throw new ServiceException("Unexpected exception" + e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import java.util.stream.Collectors;


@Component
public class DefaultFlashcardClient extends AbstractCrudClient<FlashCardDto, String> implements FlashcardClient {
@Component("flashcardClient")
public class DefaultFlashcardClient extends AbstractCrudClient<FlashCardDto, Long> implements FlashcardClient {
@Override
public String getEntityListUrl() {
return getServerAddress() + ResourceUrls.flashCards;
Expand All @@ -31,8 +31,8 @@ public String postEntityUrl() {
}

@Override
public String postBulkEntitiesUrl() {
return getServerAddress() + ResourceUrls.flashCards + BULK;
public String postBatchEntitiesUrl() {
return getServerAddress() + ResourceUrls.flashCards + ResourceUrls.batch;
}

@Override
Expand Down Expand Up @@ -75,7 +75,7 @@ public List<FlashCardDto> findByTagsIn(final Set<TagDto> tags, final PageRequest
final Map<String, String> uriVariables = setupSearchUriVariables();

final String tagNames = tags.stream()
.map(AbstractPersistableDto::getId)
.map(tag -> tag.getId().toString())
.collect(Collectors.joining(","));

uriVariables.put("tags", tagNames);
Expand Down Expand Up @@ -122,7 +122,7 @@ public FlashCardDto findByQuestion(final String question) throws ServiceExceptio
}

@Override
public List<FlashCardDto> findFlashcardsForTag(String tagId, Set<String> fields) throws FlashcardsException {
public List<FlashCardDto> findFlashcardsForTag(Long tagId, Set<String> fields) throws FlashcardsException {
final Map<String, String> uriVariables = new HashMap<String, String>();
uriVariables.put("tagId", String.valueOf(tagId));
return Arrays.asList(searchEntities(getServerAddress() + ResourceUrls.flashcardsForTag, uriVariables, FlashCardDto[].class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import java.util.*;

@Component
public class DefaultTagClient extends AbstractCrudClient<TagDto, String> implements TagClient {
@Component("tagClient")
public class DefaultTagClient extends AbstractCrudClient<TagDto, Long> implements TagClient {

@Override
public String getEntityListUrl() {
Expand All @@ -24,8 +24,8 @@ public String getEntityUrl() {
public String postEntityUrl() { return getServerAddress() + ResourceUrls.tags; }

@Override
public String postBulkEntitiesUrl() {
return getServerAddress() + ResourceUrls.tags + BULK;
public String postBatchEntitiesUrl() {
return getServerAddress() + ResourceUrls.tags + ResourceUrls.batch;
}

@Override
Expand Down Expand Up @@ -66,7 +66,7 @@ public TagDto findByName(final String name) throws ServiceException {
}

@Override
public List<TagDto> findTagsForFlashcard(final String flashcardId, final Set<String> fields) {
public List<TagDto> findTagsForFlashcard(final Long flashcardId, final Set<String> fields) {
Map<String, String> uriVariables = new HashMap<String, String>();
uriVariables.put("flashcardId", String.valueOf(flashcardId));
return Arrays.asList(searchEntities(getServerAddress() + ResourceUrls.tagsForFlashcard, uriVariables, TagDto[].class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import java.util.HashMap;
import java.util.Map;

@Component
public class DefaultUserClient extends AbstractCrudClient<UserDto, String> implements UserClient {
@Component("userClient")
public class DefaultUserClient extends AbstractCrudClient<UserDto, Long> implements UserClient {

@Override
public String getEntityListUrl() {
Expand All @@ -27,8 +27,8 @@ public String postEntityUrl() {
}

@Override
public String postBulkEntitiesUrl() {
return getServerAddress() + ResourceUrls.users + BULK;
public String postBatchEntitiesUrl() {
return getServerAddress() + ResourceUrls.users + ResourceUrls.batch;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
import org.robbins.flashcards.dto.FlashCardDto;
import org.robbins.flashcards.facade.FlashcardFacade;

public interface FlashcardClient extends FlashcardFacade, GenericRestCrudFacade<FlashCardDto, String> {
public interface FlashcardClient extends FlashcardFacade, GenericRestCrudFacade<FlashCardDto, Long> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
import org.robbins.flashcards.dto.TagDto;
import org.robbins.flashcards.facade.TagFacade;

public interface TagClient extends TagFacade, GenericRestCrudFacade<TagDto, String> {
public interface TagClient extends TagFacade, GenericRestCrudFacade<TagDto, Long> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
import org.robbins.flashcards.dto.UserDto;
import org.robbins.flashcards.facade.UserFacade;

public interface UserClient extends UserFacade, GenericRestCrudFacade<UserDto, String> {
public interface UserClient extends UserFacade, GenericRestCrudFacade<UserDto, Long> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ private ResourceUrls() {
public static final String tagsForFlashcard = "v1/flashcards/{flashcardId}/tags";

public static final String flashcardsForTag = "v1/tags/{tagId}/flashcards";

public static final String batch = "batch/";
}
22 changes: 15 additions & 7 deletions FlashCards_Client/src/main/resources/applicatonContext-client.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

<context:property-placeholder location="classpath*:application.properties" />
<context:property-placeholder location="classpath*:application.properties"/>

<bean id="objectMapper" class="org.robbins.flashcards.client.jackson.CustomObjectMapper" />
<bean id="objectMapper" class="org.robbins.flashcards.client.jackson.CustomObjectMapper"/>

<context:component-scan base-package="org.robbins.flashcards.client" />
<context:component-scan base-package="org.robbins.flashcards.client"/>

<util:map id="dtoToClientMap">
<entry key="TagDto" value-ref="tagClient" />
<entry key="FlashCardDto" value-ref="flashcardClient" />
<entry key="UserDto" value-ref="userClient" />
</util:map>

</beans>
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.springframework.data.domain.Persistable;

public abstract class AbstractPersistableDto implements Persistable<String> {
public abstract class AbstractPersistableDto implements Persistable<Long> {

private static final long serialVersionUID = -7383983165721894674L;

private String id;
private Long id;

@Override
public String getId() {
public Long getId() {
return id;
}

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

Expand Down
Loading

0 comments on commit b674457

Please sign in to comment.