diff --git a/spring-ldap-person/src/main/java/org/springframework/ldap/samples/person/service/GroupService.java b/spring-ldap-person/src/main/java/org/springframework/ldap/samples/person/service/GroupService.java index 674a74f8..bcba9818 100644 --- a/spring-ldap-person/src/main/java/org/springframework/ldap/samples/person/service/GroupService.java +++ b/spring-ldap-person/src/main/java/org/springframework/ldap/samples/person/service/GroupService.java @@ -13,13 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.ldap.samples.person.service; +package se.jayway.demo.spring.ldap.service; import java.util.List; -import java.util.Set; -import org.springframework.ldap.samples.person.domain.Group; -import org.springframework.ldap.samples.person.domain.SearchCriteria; +import se.jayway.demo.spring.ldap.domain.Group; /** * Example interface for a Group service. @@ -28,15 +26,7 @@ import org.springframework.ldap.samples.person.domain.SearchCriteria; */ public interface GroupService { - void create(String name, Set members); + Group findByPrimaryKey(String name); - void update(Group group); - - void delete(Group group); - - Group findByPrimaryKey(String name); - - List find(SearchCriteria criteria); - - List findAll(); + public List findAll(); } diff --git a/spring-ldap-person/src/main/java/org/springframework/ldap/samples/person/service/GroupServiceImpl.java b/spring-ldap-person/src/main/java/org/springframework/ldap/samples/person/service/GroupServiceImpl.java index d6c1b813..09454d52 100644 --- a/spring-ldap-person/src/main/java/org/springframework/ldap/samples/person/service/GroupServiceImpl.java +++ b/spring-ldap-person/src/main/java/org/springframework/ldap/samples/person/service/GroupServiceImpl.java @@ -13,14 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.ldap.samples.person.service; +package se.jayway.demo.spring.ldap.service; import java.util.List; -import java.util.Set; -import org.springframework.ldap.samples.person.dao.GroupDao; -import org.springframework.ldap.samples.person.domain.Group; -import org.springframework.ldap.samples.person.domain.SearchCriteria; +import se.jayway.demo.spring.ldap.dao.GroupDao; +import se.jayway.demo.spring.ldap.domain.Group; /** * Service implementation for managing the Group entity. @@ -29,57 +27,24 @@ import org.springframework.ldap.samples.person.domain.SearchCriteria; */ public class GroupServiceImpl implements GroupService { - private GroupDao groupDao; + private GroupDao groupDao; - public void setGroupDao(GroupDao groupDao) { - this.groupDao = groupDao; - } + public void setGroupDao(GroupDao groupDao) { + this.groupDao = groupDao; + } - /* - * @see org.springframework.ldap.samples.person.service.GroupService#create(java.lang.String, - * java.util.Set) - */ - public void create(String name, Set members) { + /* + * @see org.springframework.ldap.samples.person.service.GroupService#findByPrimaryKey(java.lang.String) + */ + public Group findByPrimaryKey(String name) { + return groupDao.findByPrimaryKey(name); + } - Group group = new Group(); - group.setName(name); - group.setMembers(members); + /* + * @see org.springframework.ldap.samples.person.service.GroupService#findAll() + */ + public List findAll() { + return groupDao.findAll(); + } - groupDao.create(group); - } - - /* - * @see org.springframework.ldap.samples.person.service.GroupService#update(org.springframework.ldap.samples.person.domain.Group) - */ - public void update(Group group) { - groupDao.update(group); - } - - /* - * @see org.springframework.ldap.samples.person.service.GroupService#delete(org.springframework.ldap.samples.person.domain.Group) - */ - public void delete(Group group) { - groupDao.delete(group); - } - - /* - * @see org.springframework.ldap.samples.person.service.GroupService#findByPrimaryKey(java.lang.String) - */ - public Group findByPrimaryKey(String name) { - return groupDao.findByPrimaryKey(name); - } - - /* - * @see org.springframework.ldap.samples.person.service.GroupService#findAll() - */ - public List findAll() { - return groupDao.findAll(); - } - - /* - * @see org.springframework.ldap.samples.person.service.GroupService#find(org.springframework.ldap.samples.person.domain.SearchCriteria) - */ - public List find(SearchCriteria criteria) { - return groupDao.find(criteria); - } } diff --git a/spring-ldap-person/src/main/java/org/springframework/ldap/samples/person/service/PersonService.java b/spring-ldap-person/src/main/java/org/springframework/ldap/samples/person/service/PersonService.java index 1b77697f..5e678907 100644 --- a/spring-ldap-person/src/main/java/org/springframework/ldap/samples/person/service/PersonService.java +++ b/spring-ldap-person/src/main/java/org/springframework/ldap/samples/person/service/PersonService.java @@ -13,12 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.ldap.samples.person.service; +package se.jayway.demo.spring.ldap.service; import java.util.List; -import org.springframework.ldap.samples.person.domain.Person; -import org.springframework.ldap.samples.person.domain.SearchCriteria; +import se.jayway.demo.spring.ldap.domain.Person; /** * Example interface for a Person service. @@ -28,16 +27,9 @@ import org.springframework.ldap.samples.person.domain.SearchCriteria; */ public interface PersonService { - void create(String country, String company, String fullname, - String lastname, String[] description); - void update(Person person); - void delete(Person person); - Person findByPrimaryKey(String country, String company, String name); - List find(SearchCriteria criteria); - - List findAll(); + public List findAll(); } diff --git a/spring-ldap-person/src/main/java/org/springframework/ldap/samples/person/service/PersonServiceImpl.java b/spring-ldap-person/src/main/java/org/springframework/ldap/samples/person/service/PersonServiceImpl.java index 879f0aa3..b170a246 100644 --- a/spring-ldap-person/src/main/java/org/springframework/ldap/samples/person/service/PersonServiceImpl.java +++ b/spring-ldap-person/src/main/java/org/springframework/ldap/samples/person/service/PersonServiceImpl.java @@ -1,107 +1,38 @@ -/* - * Copyright 2005-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.ldap.samples.person.service; - -import java.util.List; - -import org.apache.commons.lang.StringUtils; -import org.springframework.ldap.samples.person.dao.GroupDao; -import org.springframework.ldap.samples.person.dao.PersonDao; -import org.springframework.ldap.samples.person.domain.Person; -import org.springframework.ldap.samples.person.domain.SearchCriteria; - -/** - * Service implementation for managing the Person entity. - * - * @author Mattias Arthursson - * @author Ulrik Sandberg - */ -public class PersonServiceImpl implements PersonService { - - private PersonDao personDao; - - private GroupDao groupDao; - - /* - * @see org.springframework.ldap.samples.person.service.PersonService#create(java.lang.String, - * java.lang.String, java.lang.String, java.lang.String, - * java.lang.String[]) - */ - public void create(String country, String company, String fullname, - String lastname, String[] description) { - - Person person = new Person(); - person.setCountry(country); - person.setCompany(company); - person.setFullName(fullname); - person.setLastName(lastname); - person.setDescription(description); - - personDao.create(person); - } - - /* - * @see org.springframework.ldap.samples.person.service.PersonService#update(org.springframework.ldap.samples.person.domain.Person) - */ - public void update(Person person) { - String originalDn = person.getDn(); - personDao.update(person); - String newDn = person.getDn(); - - // If the DN has changed (i.e. if the user has been moved in the tree, - // also modify all referring groups. - // Unfortunately this doesn't work with the current version of ApacheDS, - // as the format of the DN produced by DistinguishedName is different - // from the one present in the DB (and recognized by acegi). - if (!StringUtils.equals(originalDn, newDn)) { - groupDao.updateMemberDn(originalDn, newDn); - } - } - - public void delete(Person person) { - personDao.delete(person); - } - - /* - * @see org.springframework.ldap.samples.person.service.PersonService#findByPrimaryKey(java.lang.String, - * java.lang.String, java.lang.String) - */ - public Person findByPrimaryKey(String country, String company, String name) { - return personDao.findByPrimaryKeyData(country, company, name); - } - - /* - * @see org.springframework.ldap.samples.person.service.PersonService#findAll() - */ - public List findAll() { - return personDao.findAll(); - } - - /* - * @see org.springframework.ldap.samples.person.service.PersonService#find(org.springframework.ldap.samples.person.domain.SearchCriteria) - */ - public List find(SearchCriteria criteria) { - return personDao.find(criteria); - } - - public void setPersonDao(PersonDao personDao) { - this.personDao = personDao; - } - - public void setGroupDao(GroupDao groupDao) { - this.groupDao = groupDao; - } -} +package se.jayway.demo.spring.ldap.service; + +import java.util.List; + +import org.springframework.ldap.core.DistinguishedName; + +import se.jayway.demo.spring.ldap.dao.PersonDao; +import se.jayway.demo.spring.ldap.domain.Person; + +public class PersonServiceImpl implements PersonService { + + private PersonDao personDao; + + public final void setPersonDao(PersonDao personDao) { + this.personDao = personDao; + } + + public List findAll() { + return personDao.findAll(); + } + + public Person findByPrimaryKey(String country, String company, String name) { + return personDao.findByPrimaryKey(buildDn(country, company, name)); + } + + public void update(Person person) { + personDao.update(person); + } + + private String buildDn(String country, String company, String fullName) { + DistinguishedName dn = new DistinguishedName(); + dn.add("c", country); + dn.add("ou", company); + dn.add("cn", fullName); + return dn.toString(); + } + +}