First shot at implementing traditional create, update and delete.
Cleaned up interfaces.
This commit is contained in:
@@ -23,5 +23,5 @@ import java.util.List;
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public interface CompanyDao {
|
||||
public List findByCountry(String country);
|
||||
List findByCountry(String country);
|
||||
}
|
||||
|
||||
@@ -23,5 +23,5 @@ import java.util.List;
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public interface CountryDao {
|
||||
public List findAll();
|
||||
List findAll();
|
||||
}
|
||||
|
||||
@@ -26,17 +26,17 @@ import org.springframework.ldap.samples.person.domain.SearchCriteria;
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public interface GroupDao {
|
||||
public void create(Group group);
|
||||
void create(Group group);
|
||||
|
||||
public void update(Group group);
|
||||
void update(Group group);
|
||||
|
||||
public void delete(Group group);
|
||||
void delete(Group group);
|
||||
|
||||
public Group findByPrimaryKey(String name);
|
||||
Group findByPrimaryKey(String name);
|
||||
|
||||
public List findAll();
|
||||
List findAll();
|
||||
|
||||
public List find(SearchCriteria criteria);
|
||||
List find(SearchCriteria criteria);
|
||||
|
||||
/**
|
||||
* Update all groups referring to the original DN with the new DN value.
|
||||
@@ -46,5 +46,5 @@ public interface GroupDao {
|
||||
* @param newDn
|
||||
* the new DN.
|
||||
*/
|
||||
public void updateMemberDn(String originalDn, String newDn);
|
||||
void updateMemberDn(String originalDn, String newDn);
|
||||
}
|
||||
|
||||
@@ -27,18 +27,18 @@ import org.springframework.ldap.samples.person.domain.SearchCriteria;
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public interface PersonDao {
|
||||
public void create(Person person);
|
||||
void create(Person person);
|
||||
|
||||
public void update(Person person);
|
||||
void update(Person person);
|
||||
|
||||
public void delete(Person person);
|
||||
void delete(Person person);
|
||||
|
||||
public Person findByPrimaryKey(String dn);
|
||||
Person findByPrimaryKey(String dn);
|
||||
|
||||
public Person findByPrimaryKeyData(String country, String company,
|
||||
Person findByPrimaryKeyData(String country, String company,
|
||||
String fullname);
|
||||
|
||||
public List findAll();
|
||||
List findAll();
|
||||
|
||||
public List find(SearchCriteria criteria);
|
||||
List find(SearchCriteria criteria);
|
||||
}
|
||||
|
||||
@@ -25,14 +25,13 @@ import javax.naming.NamingEnumeration;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.Attribute;
|
||||
import javax.naming.directory.Attributes;
|
||||
import javax.naming.directory.BasicAttribute;
|
||||
import javax.naming.directory.BasicAttributes;
|
||||
import javax.naming.directory.DirContext;
|
||||
import javax.naming.directory.InitialDirContext;
|
||||
import javax.naming.directory.SearchControls;
|
||||
import javax.naming.directory.SearchResult;
|
||||
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
import org.springframework.ldap.core.DirContextOperations;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.ldap.samples.person.domain.Person;
|
||||
import org.springframework.ldap.samples.person.domain.SearchCriteria;
|
||||
@@ -52,31 +51,81 @@ public class TraditionalPersonDaoImpl implements PersonDao {
|
||||
|
||||
private String base;
|
||||
|
||||
// TODO Rewrite using traditional tools
|
||||
DirContextOperations getContextToBind(Person person) {
|
||||
DirContextAdapter adapter = new DirContextAdapter();
|
||||
adapter.setAttributeValues("objectclass", new String[] { "top",
|
||||
"person", "organizationalPerson", "inetOrgPerson" });
|
||||
adapter.setAttributeValue("cn", person.getFullName());
|
||||
adapter.setAttributeValue("sn", person.getLastName());
|
||||
adapter.setAttributeValues("description", person.getDescription());
|
||||
return adapter;
|
||||
Attributes getAttributesToBind(Person person) {
|
||||
BasicAttributes attributes = new BasicAttributes();
|
||||
BasicAttribute oc = new BasicAttribute("objectclass");
|
||||
oc.add("top");
|
||||
oc.add("person");
|
||||
oc.add("organizationalPerson");
|
||||
oc.add("inetOrgPerson");
|
||||
attributes.put(oc);
|
||||
attributes.put("cn", person.getFullName());
|
||||
attributes.put("sn", person.getLastName());
|
||||
attributes.put("description", person.getDescription());
|
||||
return attributes;
|
||||
}
|
||||
|
||||
// TODO Rewrite using traditional tools
|
||||
/*
|
||||
* @see org.springframework.ldap.samples.person.dao.PersonDao#create(org.springframework.ldap.samples.person.domain.Person)
|
||||
*/
|
||||
public void create(Person person) {
|
||||
// ldapOperations.bind(buildDn(person), getContextToBind(person), null);
|
||||
DirContext ctx = createContext();
|
||||
try {
|
||||
ctx.bind(buildDn(person.getCountry(), person.getCompany(), person
|
||||
.getFullName()), null, getAttributesToBind(person));
|
||||
} catch (NamingException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
if (ctx != null) {
|
||||
try {
|
||||
ctx.close();
|
||||
} catch (Exception e) {
|
||||
// Never mind this.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO Rewrite using traditional tools
|
||||
/*
|
||||
* @see org.springframework.ldap.samples.person.dao.PersonDao#update(org.springframework.ldap.samples.person.domain.Person)
|
||||
*/
|
||||
public void update(Person person) {
|
||||
// ldapOperations.rebind(buildDn(person), getContextToBind(person),
|
||||
// null);
|
||||
DirContext ctx = createContext();
|
||||
try {
|
||||
ctx.rebind(buildDn(person.getCountry(), person.getCompany(), person
|
||||
.getFullName()), null, getAttributesToBind(person));
|
||||
} catch (NamingException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
if (ctx != null) {
|
||||
try {
|
||||
ctx.close();
|
||||
} catch (Exception e) {
|
||||
// Never mind this.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO Rewrite using traditional tools
|
||||
/*
|
||||
* @see org.springframework.ldap.samples.person.dao.PersonDao#delete(org.springframework.ldap.samples.person.domain.Person)
|
||||
*/
|
||||
public void delete(Person person) {
|
||||
// ldapOperations.unbind(buildDn(person));
|
||||
DirContext ctx = createContext();
|
||||
try {
|
||||
ctx.unbind(buildDn(person.getCountry(), person.getCompany(), person
|
||||
.getFullName()));
|
||||
} catch (NamingException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
if (ctx != null) {
|
||||
try {
|
||||
ctx.close();
|
||||
} catch (Exception e) {
|
||||
// Never mind this.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -243,5 +292,4 @@ public class TraditionalPersonDaoImpl implements PersonDao {
|
||||
public void setBase(String base) {
|
||||
this.base = base;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,15 +28,15 @@ import org.springframework.ldap.samples.person.domain.SearchCriteria;
|
||||
*/
|
||||
public interface GroupService {
|
||||
|
||||
public void create(String name, Set members);
|
||||
void create(String name, Set members);
|
||||
|
||||
public void update(Group group);
|
||||
void update(Group group);
|
||||
|
||||
public void delete(Group group);
|
||||
void delete(Group group);
|
||||
|
||||
public Group findByPrimaryKey(String name);
|
||||
Group findByPrimaryKey(String name);
|
||||
|
||||
public List find(SearchCriteria criteria);
|
||||
List find(SearchCriteria criteria);
|
||||
|
||||
public List findAll();
|
||||
List findAll();
|
||||
}
|
||||
|
||||
@@ -28,16 +28,16 @@ import org.springframework.ldap.samples.person.domain.SearchCriteria;
|
||||
*/
|
||||
public interface PersonService {
|
||||
|
||||
public void create(String country, String company, String fullname,
|
||||
void create(String country, String company, String fullname,
|
||||
String lastname, String[] description);
|
||||
|
||||
public void update(Person person);
|
||||
void update(Person person);
|
||||
|
||||
public void delete(Person person);
|
||||
void delete(Person person);
|
||||
|
||||
public Person findByPrimaryKey(String country, String company, String name);
|
||||
Person findByPrimaryKey(String country, String company, String name);
|
||||
|
||||
public List find(SearchCriteria criteria);
|
||||
List find(SearchCriteria criteria);
|
||||
|
||||
public List findAll();
|
||||
List findAll();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user