Skip to content

Commit 0eb6404

Browse files
author
eugenp
committed
work on search and integration testing for search
1 parent 75977aa commit 0eb6404

25 files changed

Lines changed: 653 additions & 410 deletions

‎eclipse/INTEGRATION-SINGLE.launch‎

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<launchConfiguration type="org.eclipse.jdt.junit.launchconfig">
3-
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
4-
<listEntry value="/rest/src/test/java/org/rest/sec/client/UserClientRESTIntegrationTest.java"/>
5-
</listAttribute>
6-
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
7-
<listEntry value="1"/>
8-
</listAttribute>
9-
<mapAttribute key="org.eclipse.debug.core.environmentVariables">
10-
<mapEntry key="persistenceTarget" value="test"/>
11-
<mapEntry key="target" value="dev"/>
12-
</mapAttribute>
13-
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/>
14-
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
15-
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
16-
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/>
17-
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.m2e.launchconfig.classpathProvider"/>
18-
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.rest.sec.client.UserClientRESTIntegrationTest"/>
19-
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="rest"/>
20-
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.m2e.launchconfig.sourcepathProvider"/>
21-
</launchConfiguration>
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<launchConfiguration type="org.eclipse.jdt.junit.launchconfig">
3+
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
4+
<listEntry value="/rest/src/test/java/org/rest/test/suite/IntegrationPersistenceTestSuite.java"/>
5+
</listAttribute>
6+
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
7+
<listEntry value="1"/>
8+
</listAttribute>
9+
<mapAttribute key="org.eclipse.debug.core.environmentVariables">
10+
<mapEntry key="persistenceTarget" value="test"/>
11+
<mapEntry key="target" value="dev"/>
12+
</mapAttribute>
13+
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/>
14+
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
15+
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
16+
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/>
17+
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.m2e.launchconfig.classpathProvider"/>
18+
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.rest.test.suite.IntegrationPersistenceTestSuite"/>
19+
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="rest"/>
20+
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.m2e.launchconfig.sourcepathProvider"/>
21+
</launchConfiguration>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.rest.common;
2+
3+
public interface INameableEntity extends IEntity {
4+
5+
String getName();
6+
7+
}

‎src/main/java/org/rest/persistence/service/AbstractService.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.List;
44

5+
import org.apache.commons.lang3.tuple.ImmutablePair;
56
import org.rest.common.IEntity;
67
import org.rest.persistence.event.EntityCreatedEvent;
78
import org.slf4j.Logger;
@@ -34,6 +35,13 @@ public AbstractService(final Class<T> clazzToSet) {
3435

3536
// API
3637

38+
// search
39+
40+
@Override
41+
public List<T> search(final ImmutablePair<String, ?>... constraints) {
42+
throw new UnsupportedOperationException();
43+
}
44+
3745
// find/get
3846

3947
@Override

‎src/main/java/org/rest/persistence/service/IService.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
package org.rest.persistence.service;
22

3+
import java.util.List;
4+
5+
import org.apache.commons.lang3.tuple.ImmutablePair;
36
import org.rest.common.IEntity;
47
import org.rest.common.IRestDao;
58
import org.springframework.data.domain.Page;
69

710
public interface IService<T extends IEntity> extends IRestDao<T> {
811

12+
// search
13+
14+
List<T> search(final ImmutablePair<String, ?>... constraints);
15+
916
// find - all
1017

1118
Page<T> findPaginated(final int page, final int size, final String sortBy);

‎src/main/java/org/rest/sec/dto/User.java‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import javax.xml.bind.annotation.XmlRootElement;
66

77
import org.apache.commons.lang.builder.ToStringBuilder;
8-
import org.rest.common.IEntity;
8+
import org.rest.common.INameableEntity;
99
import org.rest.sec.model.Principal;
1010
import org.rest.sec.model.Role;
1111

@@ -15,7 +15,7 @@
1515

1616
@XmlRootElement
1717
@XStreamAlias("user")
18-
public class User implements IEntity {
18+
public class User implements INameableEntity {
1919

2020
@XStreamAsAttribute
2121
private Long id;
@@ -62,6 +62,7 @@ public void setId(final Long idToSet) {
6262
id = idToSet;
6363
}
6464

65+
@Override
6566
public String getName() {
6667
return name;
6768
}

‎src/main/java/org/rest/sec/model/Principal.java‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
import javax.xml.bind.annotation.XmlRootElement;
1515

1616
import org.apache.commons.lang.builder.ToStringBuilder;
17-
import org.rest.common.IEntity;
17+
import org.rest.common.INameableEntity;
1818

1919
import com.thoughtworks.xstream.annotations.XStreamImplicit;
2020

2121
@Entity
2222
@XmlRootElement
23-
public class Principal implements IEntity {
23+
public class Principal implements INameableEntity {
2424

2525
@Id
2626
@GeneratedValue(strategy = GenerationType.AUTO)
@@ -31,11 +31,11 @@ public class Principal implements IEntity {
3131
@Column(nullable = false)
3232
private String password;
3333
//@formatter:off
34-
@ManyToMany( /*cascade = { CascadeType.REMOVE },*/fetch = FetchType.EAGER )
35-
@JoinTable( joinColumns = { @JoinColumn( name = "PRINCIPAL_ID",referencedColumnName = "PRINCIPAL_ID" ) },inverseJoinColumns = { @JoinColumn( name = "ROLE_ID",referencedColumnName = "ROLE_ID" ) } )
36-
@XStreamImplicit
37-
private Set< Role > roles;
38-
//@formatter:on
34+
@ManyToMany( /*cascade = { CascadeType.REMOVE },*/fetch = FetchType.EAGER )
35+
@JoinTable( joinColumns = { @JoinColumn( name = "PRINCIPAL_ID",referencedColumnName = "PRINCIPAL_ID" ) },inverseJoinColumns = { @JoinColumn( name = "ROLE_ID",referencedColumnName = "ROLE_ID" ) } )
36+
@XStreamImplicit
37+
private Set< Role > roles;
38+
//@formatter:on
3939

4040
public Principal() {
4141
super();
@@ -61,6 +61,7 @@ public void setId(final Long idToSet) {
6161
id = idToSet;
6262
}
6363

64+
@Override
6465
public String getName() {
6566
return name;
6667
}

‎src/main/java/org/rest/sec/model/Privilege.java‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
import javax.persistence.Id;
88
import javax.xml.bind.annotation.XmlRootElement;
99

10-
import org.rest.common.IEntity;
10+
import org.rest.common.INameableEntity;
1111

1212
@Entity
1313
@XmlRootElement
14-
public class Privilege implements IEntity {
14+
public class Privilege implements INameableEntity {
1515

1616
@Id
1717
@GeneratedValue(strategy = GenerationType.AUTO)
@@ -41,6 +41,7 @@ public void setId(final Long idToSet) {
4141
id = idToSet;
4242
}
4343

44+
@Override
4445
public String getName() {
4546
return name;
4647
}

‎src/main/java/org/rest/sec/model/Role.java‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import javax.xml.bind.annotation.XmlRootElement;
1515

1616
import org.apache.commons.lang.builder.ToStringBuilder;
17-
import org.rest.common.IEntity;
17+
import org.rest.common.INameableEntity;
1818

1919
import com.thoughtworks.xstream.annotations.XStreamAlias;
2020
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
@@ -23,7 +23,7 @@
2323
@Entity
2424
@XmlRootElement
2525
@XStreamAlias("role")
26-
public class Role implements IEntity {
26+
public class Role implements INameableEntity {
2727

2828
@Id
2929
@GeneratedValue(strategy = GenerationType.AUTO)
@@ -34,11 +34,11 @@ public class Role implements IEntity {
3434
private String name;
3535

3636
//@formatter:off
37-
@ManyToMany( /*cascade = { CascadeType.REMOVE },*/fetch = FetchType.EAGER )
38-
@JoinTable( joinColumns = { @JoinColumn( name = "ROLE_ID",referencedColumnName = "ROLE_ID" ) },inverseJoinColumns = { @JoinColumn( name = "PRIV_ID",referencedColumnName = "PRIV_ID" ) } )
39-
@XStreamImplicit
40-
private Set< Privilege > privileges;
41-
//@formatter:on
37+
@ManyToMany( /*cascade = { CascadeType.REMOVE },*/fetch = FetchType.EAGER )
38+
@JoinTable( joinColumns = { @JoinColumn( name = "ROLE_ID",referencedColumnName = "ROLE_ID" ) },inverseJoinColumns = { @JoinColumn( name = "PRIV_ID",referencedColumnName = "PRIV_ID" ) } )
39+
@XStreamImplicit
40+
private Set< Privilege > privileges;
41+
//@formatter:on
4242

4343
public Role() {
4444
super();
@@ -67,6 +67,7 @@ public void setId(final Long idToSet) {
6767
id = idToSet;
6868
}
6969

70+
@Override
7071
public String getName() {
7172
return name;
7273
}
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
package org.rest.sec.persistence.service;
22

3-
import java.util.List;
4-
5-
import org.apache.commons.lang3.tuple.ImmutablePair;
63
import org.rest.persistence.service.IService;
74
import org.rest.sec.model.Role;
85

96
public interface IRoleService extends IService<Role> {
107

118
Role findByName(final String name);
129

13-
List<Role> search(final ImmutablePair<String, ?>... constraints);
14-
1510
}

‎src/main/java/org/rest/sec/persistence/service/impl/PrivilegeServiceImpl.java‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
package org.rest.sec.persistence.service.impl;
22

3+
import java.util.List;
4+
5+
import org.apache.commons.lang3.tuple.ImmutablePair;
36
import org.rest.persistence.service.AbstractService;
47
import org.rest.sec.model.Privilege;
58
import org.rest.sec.persistence.dao.IPrivilegeJpaDAO;
69
import org.rest.sec.persistence.service.IPrivilegeService;
10+
import org.rest.sec.util.SearchSecUtil;
711
import org.springframework.beans.factory.annotation.Autowired;
12+
import org.springframework.data.jpa.domain.Specification;
13+
import org.springframework.data.jpa.domain.Specifications;
814
import org.springframework.stereotype.Service;
915
import org.springframework.transaction.annotation.Transactional;
1016

17+
import com.google.common.collect.Lists;
18+
1119
@Service
1220
@Transactional
1321
public class PrivilegeServiceImpl extends AbstractService<Privilege> implements IPrivilegeService {
@@ -21,6 +29,24 @@ public PrivilegeServiceImpl() {
2129

2230
// API
2331

32+
// search
33+
34+
@Override
35+
public List<Privilege> search(final ImmutablePair<String, ?>... constraints) {
36+
final Specification<Privilege> firstSpec = SearchSecUtil.resolveConstraint(constraints[0], Privilege.class);
37+
Specifications<Privilege> specifications = Specifications.where(firstSpec);
38+
for (int i = 1; i < constraints.length; i++) {
39+
specifications = specifications.and(SearchSecUtil.resolveConstraint(constraints[i], Privilege.class));
40+
}
41+
if (firstSpec == null) {
42+
return Lists.newArrayList();
43+
}
44+
45+
return getDao().findAll(specifications);
46+
}
47+
48+
// find
49+
2450
@Override
2551
public Privilege findByName(final String name) {
2652
return getDao().findByName(name);

0 commit comments

Comments
 (0)