comparison artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java @ 150:78a27a6b3f1f

Implemented the listUsers() method in the artifact database. artifacts/trunk@1375 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 03 Mar 2011 07:10:44 +0000
parents c69abd07bdd0
children 7e5619115d5b
comparison
equal deleted inserted replaced
149:c69abd07bdd0 150:78a27a6b3f1f
933 } 933 }
934 934
935 // User API 935 // User API
936 936
937 public Document listUsers(CallMeta callMeta) 937 public Document listUsers(CallMeta callMeta)
938 throws ArtifactDatabaseException {
939 throw new ArtifactDatabaseException("Not implemented, yet!");
940
941 }
942
943 public Document createUser(Document data, CallMeta callMeta)
944 throws ArtifactDatabaseException 938 throws ArtifactDatabaseException
945 { 939 {
946 UserFactory factory = getUserFactory(); 940 UserFactory factory = getUserFactory();
947 941
948 if (factory == null) { 942 if (factory == null) {
949 throw new ArtifactDatabaseException(NO_SUCH_FACTORY); 943 throw new ArtifactDatabaseException(NO_SUCH_FACTORY);
950 } 944 }
951 945
952 String name = XMLUtils.xpathString( 946 User[] users = factory.getUsers(context);
953 data, XPATH_USERNAME, ArtifactNamespaceContext.INSTANCE); 947
954 948 if (users != null) {
955 if (name == null || name.length() == 0) { 949 logger.debug(users.length + " users found in the backend.");
956 logger.warn("User without username not accepted!");
957 throw new ArtifactDatabaseException(NO_USERNAME);
958 }
959
960 // TODO Extract the role is contained as node in the xml document.
961 Document role = XMLUtils.newDocument();
962
963 User newUser = null;
964
965 try {
966 newUser = factory.createUser(name, role, context);
967 }
968 catch (Exception e) {
969 logger.error(e.getMessage(), e);
970 throw new ArtifactDatabaseException(USER_CREATION_FAILED);
971 } 950 }
972 951
973 Document result = XMLUtils.newDocument(); 952 Document result = XMLUtils.newDocument();
974 953
975 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( 954 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
976 result, 955 result,
977 ArtifactNamespaceContext.NAMESPACE_URI, 956 ArtifactNamespaceContext.NAMESPACE_URI,
978 ArtifactNamespaceContext.NAMESPACE_PREFIX); 957 ArtifactNamespaceContext.NAMESPACE_PREFIX);
979 958
959 Element root = ec.create("users");
960 result.appendChild(root);
961
962 for (User user: users) {
963 Element ue = ec.create("user");
964 ec.addAttr(ue, "name", user.getName());
965
966 // TODO append the role of the user.
967 root.appendChild(ue);
968 }
969
970 return result;
971 }
972
973 public Document createUser(Document data, CallMeta callMeta)
974 throws ArtifactDatabaseException
975 {
976 UserFactory factory = getUserFactory();
977
978 if (factory == null) {
979 throw new ArtifactDatabaseException(NO_SUCH_FACTORY);
980 }
981
982 String name = XMLUtils.xpathString(
983 data, XPATH_USERNAME, ArtifactNamespaceContext.INSTANCE);
984
985 if (name == null || name.length() == 0) {
986 logger.warn("User without username not accepted!");
987 throw new ArtifactDatabaseException(NO_USERNAME);
988 }
989
990 // TODO Extract the role is contained as node in the xml document.
991 Document role = XMLUtils.newDocument();
992
993 User newUser = null;
994
995 try {
996 newUser = factory.createUser(name, role, context);
997 }
998 catch (Exception e) {
999 logger.error(e.getMessage(), e);
1000 throw new ArtifactDatabaseException(USER_CREATION_FAILED);
1001 }
1002
1003 Document result = XMLUtils.newDocument();
1004
1005 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
1006 result,
1007 ArtifactNamespaceContext.NAMESPACE_URI,
1008 ArtifactNamespaceContext.NAMESPACE_PREFIX);
1009
980 Element root = ec.create("result"); 1010 Element root = ec.create("result");
981 1011
982 if (newUser != null) { 1012 if (newUser != null) {
983 root.setTextContent("SUCCESS"); 1013 root.setTextContent("SUCCESS");
984 } 1014 }

http://dive4elements.wald.intevation.org