Mercurial > dive4elements > framework
comparison artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java @ 149:c69abd07bdd0
Implemented the createUser() method in the artifact database.
artifacts/trunk@1374 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 03 Mar 2011 06:53:51 +0000 |
parents | 6f1e8c08f747 |
children | 78a27a6b3f1f |
comparison
equal
deleted
inserted
replaced
148:101a52d3ad08 | 149:c69abd07bdd0 |
---|---|
18 import de.intevation.artifacts.ArtifactSerializer; | 18 import de.intevation.artifacts.ArtifactSerializer; |
19 import de.intevation.artifacts.CallContext; | 19 import de.intevation.artifacts.CallContext; |
20 import de.intevation.artifacts.CallMeta; | 20 import de.intevation.artifacts.CallMeta; |
21 import de.intevation.artifacts.Service; | 21 import de.intevation.artifacts.Service; |
22 import de.intevation.artifacts.ServiceFactory; | 22 import de.intevation.artifacts.ServiceFactory; |
23 import de.intevation.artifacts.User; | |
23 import de.intevation.artifacts.UserFactory; | 24 import de.intevation.artifacts.UserFactory; |
24 | 25 |
25 import java.io.IOException; | 26 import java.io.IOException; |
26 import java.io.OutputStream; | 27 import java.io.OutputStream; |
27 | 28 |
155 * Error message issued if the deserialization of | 156 * Error message issued if the deserialization of |
156 * an artifact to be imported fails. | 157 * an artifact to be imported fails. |
157 */ | 158 */ |
158 public static final String INVALID_ARTIFACT = | 159 public static final String INVALID_ARTIFACT = |
159 "Invalid artifact"; | 160 "Invalid artifact"; |
161 | |
162 | |
163 // User constants | |
164 | |
165 /** | |
166 * Error message issued if the creation of a user failed. | |
167 */ | |
168 public static final String USER_CREATION_FAILED = | |
169 "Creation of user failed."; | |
170 | |
171 /** XPath to figure out the name of a new user.*/ | |
172 public static final String XPATH_USERNAME = | |
173 "/art:action/art:user/@name"; | |
174 | |
175 /** XPath to figure out the role of a new user.*/ | |
176 public static final String XPATH_USERROLE = | |
177 "/art:action/art:user/art:role"; | |
178 | |
179 /** Error message if no username is given for user creation.*/ | |
180 public static final String NO_USERNAME = | |
181 "Invalid username"; | |
182 | |
160 | 183 |
161 /** | 184 /** |
162 * Inner class that implements the call context handed | 185 * Inner class that implements the call context handed |
163 * to the methods calls describe(), feed(), etc. of the artifact. | 186 * to the methods calls describe(), feed(), etc. of the artifact. |
164 */ | 187 */ |
565 | 588 |
566 public ArtifactFactory getArtifactFactory(String factoryName) { | 589 public ArtifactFactory getArtifactFactory(String factoryName) { |
567 return (ArtifactFactory)name2factory.get(factoryName); | 590 return (ArtifactFactory)name2factory.get(factoryName); |
568 } | 591 } |
569 | 592 |
593 public UserFactory getUserFactory() { | |
594 return userFactory; | |
595 } | |
596 | |
570 public Document createArtifactWithFactory( | 597 public Document createArtifactWithFactory( |
571 String factoryName, | 598 String factoryName, |
572 CallMeta callMeta, | 599 CallMeta callMeta, |
573 Document data | 600 Document data |
574 ) | 601 ) |
912 throw new ArtifactDatabaseException("Not implemented, yet!"); | 939 throw new ArtifactDatabaseException("Not implemented, yet!"); |
913 | 940 |
914 } | 941 } |
915 | 942 |
916 public Document createUser(Document data, CallMeta callMeta) | 943 public Document createUser(Document data, CallMeta callMeta) |
917 throws ArtifactDatabaseException { | 944 throws ArtifactDatabaseException |
918 throw new ArtifactDatabaseException("Not implemented, yet!"); | 945 { |
946 UserFactory factory = getUserFactory(); | |
947 | |
948 if (factory == null) { | |
949 throw new ArtifactDatabaseException(NO_SUCH_FACTORY); | |
950 } | |
951 | |
952 String name = XMLUtils.xpathString( | |
953 data, XPATH_USERNAME, ArtifactNamespaceContext.INSTANCE); | |
954 | |
955 if (name == null || name.length() == 0) { | |
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 } | |
972 | |
973 Document result = XMLUtils.newDocument(); | |
974 | |
975 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( | |
976 result, | |
977 ArtifactNamespaceContext.NAMESPACE_URI, | |
978 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
979 | |
980 Element root = ec.create("result"); | |
981 | |
982 if (newUser != null) { | |
983 root.setTextContent("SUCCESS"); | |
984 } | |
985 else { | |
986 root.setTextContent("FAILURE"); | |
987 } | |
988 | |
989 result.appendChild(root); | |
990 | |
991 return result; | |
919 } | 992 } |
920 | 993 |
921 public Document deleteUser(String userId, CallMeta callMeta) | 994 public Document deleteUser(String userId, CallMeta callMeta) |
922 throws ArtifactDatabaseException { | 995 throws ArtifactDatabaseException { |
923 throw new ArtifactDatabaseException("Not implemented, yet!"); | 996 throw new ArtifactDatabaseException("Not implemented, yet!"); |