Skip to content

Commit

Permalink
#119 Ability to search for groups
Browse files Browse the repository at this point in the history
  • Loading branch information
tktong committed Jan 8, 2016
1 parent 91523fc commit 4daa8a7
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ dcsc-web/build/**
utilities/build/**
**/build/**
bin/**
out/**
.DS_STORE
.settings
.project
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.dcsc.athena.services;

import org.springframework.stereotype.Service;

@Service
public class TutorUserService {
}
8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ subprojects {
thymeleafVersion = '2.1.2.RELEASE'
thymeleafLayoutVersion = '1.2.8'
}

dependencies {
testCompile "junit:junit:$junitVersion"
testCompile "org.mockito:mockito-all:$mockitoVersion"
testCompile "org.powermock:powermock-mockito-release-full:$powerMockVersion"
testCompile "org.springframework:spring-test:$springVersion"
testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion"
}
}

task wrapper(type: Wrapper) {
Expand Down
12 changes: 12 additions & 0 deletions core/src/main/java/org/dcsc/core/user/group/Group.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.dcsc.core.user.group;

import javax.persistence.*;
import java.util.List;

@Entity
@Table(name = "dcsc_groups", schema = "dcsc_accounts")
Expand All @@ -13,6 +14,9 @@ public class Group {
@Column(name = "name")
private String name;

@OneToMany(mappedBy = "group", fetch = FetchType.EAGER)
private List<UserGroup> userGroups;

public long getId() {
return id;
}
Expand All @@ -28,4 +32,12 @@ public String getName() {
public void setName(String name) {
this.name = name;
}

public List<UserGroup> getUserGroups() {
return userGroups;
}

public void setUserGroups(List<UserGroup> userGroups) {
this.userGroups = userGroups;
}
}
11 changes: 11 additions & 0 deletions core/src/main/java/org/dcsc/core/user/group/GroupRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.dcsc.core.user.group;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
public interface GroupRepository extends JpaRepository<Group, Long> {
Optional<Group> findGroupByName(String name);
}
18 changes: 18 additions & 0 deletions core/src/main/java/org/dcsc/core/user/group/GroupService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.dcsc.core.user.group;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class GroupService {
@Autowired
private GroupRepository groupRepository;

// TODO: Use a more appropriate exception
@Transactional(readOnly = true)
public Group getGroup(String groupName) throws Exception {
return groupRepository.findGroupByName(groupName)
.orElseThrow(() -> new Exception(String.format("Could not find group with name - %s", groupName)));
}
}
2 changes: 1 addition & 1 deletion src/main/resources
Submodule resources updated from e84622 to 8e7b5b
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.dcsc.utilities.converter;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;

import javax.persistence.AttributeConverter;
import java.sql.Timestamp;
import java.time.LocalDateTime;

@RunWith(MockitoJUnitRunner.class)
public class LocalDateTimeConverterTest {
private static final AttributeConverter<LocalDateTime, Timestamp> converter = new LocalDateTimeConverter();

@Test
public void convertToDatabaseColumnWithNullLocalDateTime() {
Assert.assertNull(converter.convertToDatabaseColumn(null));
}

@Test
public void convertToDatabaseColumn() {
LocalDateTime localDateTime = LocalDateTime.now();

Assert.assertEquals(Timestamp.valueOf(localDateTime), converter.convertToDatabaseColumn(localDateTime));
}

@Test
public void convertToEntityAttributeWithNullTimestamp() {
Assert.assertNull(converter.convertToEntityAttribute(null));
}

@Test
public void convertToEntityAttribute() {
LocalDateTime localDateTime = LocalDateTime.now();
Timestamp timestamp = Timestamp.valueOf(localDateTime);

Assert.assertEquals(localDateTime, converter.convertToEntityAttribute(timestamp));
}
}

0 comments on commit 4daa8a7

Please sign in to comment.