summaryrefslogtreecommitdiffstats
path: root/base/common/src/com/netscape/cms/servlet/profile
diff options
context:
space:
mode:
authorAde Lee <alee@redhat.com>2012-07-24 12:49:36 -0400
committerAde Lee <alee@redhat.com>2012-07-25 10:36:41 -0400
commit2a3125d54365bf1806633c3301ce59fdb21461e4 (patch)
tree256b9c6f8d13b8d1b2562b9042fec65156718cd9 /base/common/src/com/netscape/cms/servlet/profile
parent5fd74e0e0c9407306e99ef4fd2e776cb911ee94a (diff)
downloadpki-2a3125d54365bf1806633c3301ce59fdb21461e4.tar.gz
pki-2a3125d54365bf1806633c3301ce59fdb21461e4.tar.xz
pki-2a3125d54365bf1806633c3301ce59fdb21461e4.zip
Merge most DAO objects into the ResourceService files
Diffstat (limited to 'base/common/src/com/netscape/cms/servlet/profile')
-rw-r--r--base/common/src/com/netscape/cms/servlet/profile/ProfileResourceService.java176
-rw-r--r--base/common/src/com/netscape/cms/servlet/profile/model/ProfileDAO.java214
2 files changed, 168 insertions, 222 deletions
diff --git a/base/common/src/com/netscape/cms/servlet/profile/ProfileResourceService.java b/base/common/src/com/netscape/cms/servlet/profile/ProfileResourceService.java
index 7e8a32424..c39125876 100644
--- a/base/common/src/com/netscape/cms/servlet/profile/ProfileResourceService.java
+++ b/base/common/src/com/netscape/cms/servlet/profile/ProfileResourceService.java
@@ -18,26 +18,186 @@
package com.netscape.cms.servlet.profile;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Locale;
+
+import javax.ws.rs.Path;
+import javax.ws.rs.core.UriBuilder;
+
+import com.netscape.certsrv.apps.CMS;
+import com.netscape.certsrv.base.EBaseException;
+import com.netscape.certsrv.profile.EProfileException;
+import com.netscape.certsrv.profile.IProfile;
+import com.netscape.certsrv.profile.IProfileInput;
+import com.netscape.certsrv.profile.IProfileSubsystem;
import com.netscape.cms.servlet.base.CMSResourceService;
-import com.netscape.cms.servlet.profile.model.ProfileDAO;
import com.netscape.cms.servlet.profile.model.ProfileData;
+import com.netscape.cms.servlet.profile.model.ProfileDataInfo;
import com.netscape.cms.servlet.profile.model.ProfileDataInfos;
+import com.netscape.cms.servlet.profile.model.ProfileInput;
/**
* @author alee
*
*/
public class ProfileResourceService extends CMSResourceService implements ProfileResource {
- @Override
- public ProfileData retrieveProfile(String id) {
+
+ private IProfileSubsystem ps = (IProfileSubsystem) CMS.getSubsystem(IProfileSubsystem.ID);
+
+ public ProfileDataInfos listProfiles() {
+ List<ProfileDataInfo> list = new ArrayList<ProfileDataInfo>();
+ ProfileDataInfos infos = new ProfileDataInfos();
+
+ if (ps == null) {
+ return null;
+ }
+
+ Enumeration<String> profileIds = ps.getProfileIds();
+ if (profileIds != null) {
+ while (profileIds.hasMoreElements()) {
+ String id = profileIds.nextElement();
+ ProfileDataInfo info = null;
+ try {
+ info = createProfileDataInfo(id);
+ } catch (EBaseException e) {
+ continue;
+ }
+
+ if (info != null) {
+ list.add(info);
+ }
+ }
+ }
+
+ infos.setProfileInfos(list);
+ return infos;
+ }
+
+ public ProfileData retrieveProfile(String profileId) throws ProfileNotFoundException {
ProfileData data = null;
- ProfileDAO dao = new ProfileDAO();
- data = dao.getProfile(id);
+
+ if (ps == null) {
+ return null;
+ }
+
+ Enumeration<String> profileIds = ps.getProfileIds();
+
+ IProfile profile = null;
+ if (profileIds != null) {
+ while (profileIds.hasMoreElements()) {
+ String id = profileIds.nextElement();
+
+ if (id.equals(profileId)) {
+
+ try {
+ profile = ps.getProfile(profileId);
+ } catch (EProfileException e) {
+ e.printStackTrace();
+ throw new ProfileNotFoundException(profileId);
+ }
+ break;
+ }
+ }
+ }
+
+ if (profile == null) {
+ throw new ProfileNotFoundException(profileId);
+ }
+
+ try {
+ data = createProfileData(profileId);
+ } catch (EBaseException e) {
+ e.printStackTrace();
+ throw new ProfileNotFoundException(profileId);
+ }
+
return data;
}
- public ProfileDataInfos listProfiles() {
- ProfileDAO dao = new ProfileDAO();
- return dao.listProfiles(uriInfo);
+ public ProfileData createProfileData(String profileId) throws EBaseException {
+
+ IProfile profile;
+
+ try {
+ profile = ps.getProfile(profileId);
+ } catch (EProfileException e) {
+ e.printStackTrace();
+ throw new ProfileNotFoundException(profileId);
+ }
+
+ ProfileData data = new ProfileData();
+
+ Locale locale = Locale.getDefault();
+ String name = profile.getName(locale);
+ String desc = profile.getDescription(locale);
+
+ data.setName(name);
+ data.setDescription(desc);
+ data.setIsEnabled(ps.isProfileEnable(profileId));
+ data.setIsVisible(profile.isVisible());
+ data.setEnabledBy(ps.getProfileEnableBy(profileId));
+ data.setId(profileId);
+
+ Enumeration<String> inputIds = profile.getProfileInputIds();
+
+ String inputName = null;
+
+ if (inputIds != null) {
+ while (inputIds.hasMoreElements()) {
+ String inputId = inputIds.nextElement();
+ IProfileInput profileInput = profile.getProfileInput(inputId);
+
+ if (profileInput == null) {
+ continue;
+ }
+ inputName = profileInput.getName(locale);
+
+ Enumeration<String> inputNames = profileInput.getValueNames();
+
+ ProfileInput input = data.addProfileInput(inputName);
+
+ String curInputName = null;
+ while (inputNames.hasMoreElements()) {
+ curInputName = inputNames.nextElement();
+
+ if (curInputName != null && !curInputName.equals("")) {
+ input.setInputAttr(curInputName, "");
+ }
+
+ }
+ }
+ }
+
+ return data;
+
+ }
+
+ public ProfileDataInfo createProfileDataInfo(String profileId) throws EBaseException {
+
+ if (profileId == null) {
+ throw new EBaseException("Error creating ProfileDataInfo.");
+ }
+ ProfileDataInfo ret = null;
+
+ IProfile profile = null;
+
+ profile = ps.getProfile(profileId);
+ if (profile == null) {
+ return null;
+ }
+
+ ret = new ProfileDataInfo();
+
+ ret.setProfileId(profileId);
+
+ Path profilePath = ProfileResource.class.getAnnotation(Path.class);
+
+ UriBuilder profileBuilder = uriInfo.getBaseUriBuilder();
+ profileBuilder.path(profilePath.value() + "/" + profileId);
+ ret.setProfileURL(profileBuilder.build().toString());
+
+ return ret;
}
}
diff --git a/base/common/src/com/netscape/cms/servlet/profile/model/ProfileDAO.java b/base/common/src/com/netscape/cms/servlet/profile/model/ProfileDAO.java
deleted file mode 100644
index 372570a53..000000000
--- a/base/common/src/com/netscape/cms/servlet/profile/model/ProfileDAO.java
+++ /dev/null
@@ -1,214 +0,0 @@
-// --- BEGIN COPYRIGHT BLOCK ---
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; version 2 of the License.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License along
-// with this program; if not, write to the Free Software Foundation, Inc.,
-// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-//
-// (C) 2011 Red Hat, Inc.
-// All rights reserved.
-// --- END COPYRIGHT BLOCK ---
-package com.netscape.cms.servlet.profile.model;
-
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.Locale;
-
-import javax.ws.rs.Path;
-import javax.ws.rs.core.UriBuilder;
-import javax.ws.rs.core.UriInfo;
-
-import com.netscape.certsrv.apps.CMS;
-import com.netscape.certsrv.base.EBaseException;
-import com.netscape.certsrv.profile.EProfileException;
-import com.netscape.certsrv.profile.IProfile;
-import com.netscape.certsrv.profile.IProfileInput;
-import com.netscape.certsrv.profile.IProfileSubsystem;
-import com.netscape.cms.servlet.profile.ProfileNotFoundException;
-import com.netscape.cms.servlet.profile.ProfileResource;
-
-/**
- * @author alee
- *
- */
-public class ProfileDAO {
-
- private IProfileSubsystem ps;
-
- public ProfileDAO() {
- ps = (IProfileSubsystem) CMS.getSubsystem(IProfileSubsystem.ID);
- }
-
- /**
- * Returns list of profiles
- */
-
- public ProfileDataInfos listProfiles(UriInfo uriInfo)
- {
-
- List<ProfileDataInfo> list = new ArrayList<ProfileDataInfo>();
- ProfileDataInfos infos = new ProfileDataInfos();
-
- if (ps == null) {
- return null;
- }
-
- Enumeration<String> profileIds = ps.getProfileIds();
-
- if (profileIds != null) {
- while (profileIds.hasMoreElements()) {
- String id = profileIds.nextElement();
- ProfileDataInfo info = null;
- try {
- info = createProfileDataInfo(id, uriInfo);
- } catch (EBaseException e) {
- continue;
- }
-
- if (info != null) {
- list.add(info);
- }
- }
- }
-
- infos.setProfileInfos(list);
-
- return infos;
- }
-
- public ProfileData getProfile(String profileId) throws ProfileNotFoundException {
- ProfileData data = null;
-
- if (ps == null) {
- return null;
- }
-
- Enumeration<String> profileIds = ps.getProfileIds();
-
- IProfile profile = null;
- if (profileIds != null) {
- while (profileIds.hasMoreElements()) {
- String id = profileIds.nextElement();
-
- if (id.equals(profileId)) {
-
- try {
- profile = ps.getProfile(profileId);
- } catch (EProfileException e) {
- e.printStackTrace();
- throw new ProfileNotFoundException(profileId);
- }
- break;
- }
- }
- }
-
- if (profile == null) {
- throw new ProfileNotFoundException(profileId);
- }
-
- try {
- data = createProfileData(profileId);
- } catch (EBaseException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- throw new ProfileNotFoundException(profileId);
- }
-
- return data;
- }
-
- public ProfileData createProfileData(String profileId) throws EBaseException {
-
- IProfile profile;
-
- try {
- profile = ps.getProfile(profileId);
- } catch (EProfileException e) {
- e.printStackTrace();
- throw new ProfileNotFoundException(profileId);
- }
-
- ProfileData data = new ProfileData();
-
- Locale locale = Locale.getDefault();
- String name = profile.getName(locale);
- String desc = profile.getDescription(locale);
-
- data.setName(name);
- data.setDescription(desc);
- data.setIsEnabled(ps.isProfileEnable(profileId));
- data.setIsVisible(profile.isVisible());
- data.setEnabledBy(ps.getProfileEnableBy(profileId));
- data.setId(profileId);
-
- Enumeration<String> inputIds = profile.getProfileInputIds();
-
- String inputName = null;
-
- if (inputIds != null) {
- while (inputIds.hasMoreElements()) {
- String inputId = inputIds.nextElement();
- IProfileInput profileInput = profile.getProfileInput(inputId);
-
- if (profileInput == null) {
- continue;
- }
- inputName = profileInput.getName(locale);
-
- Enumeration<String> inputNames = profileInput.getValueNames();
-
- ProfileInput input = data.addProfileInput(inputName);
-
- String curInputName = null;
- while (inputNames.hasMoreElements()) {
- curInputName = inputNames.nextElement();
-
- if (curInputName != null && !curInputName.equals("")) {
- input.setInputAttr(curInputName, "");
- }
-
- }
- }
- }
-
- return data;
-
- }
-
- public ProfileDataInfo createProfileDataInfo(String profileId, UriInfo uriInfo) throws EBaseException {
-
- if (profileId == null) {
- throw new EBaseException("Error creating ProfileDataInfo.");
- }
- ProfileDataInfo ret = null;
-
- IProfile profile = null;
-
- profile = ps.getProfile(profileId);
- if (profile == null) {
- return null;
- }
-
- ret = new ProfileDataInfo();
-
- ret.setProfileId(profileId);
-
- Path profilePath = ProfileResource.class.getAnnotation(Path.class);
-
- UriBuilder profileBuilder = uriInfo.getBaseUriBuilder();
- profileBuilder.path(profilePath.value() + "/" + profileId);
- ret.setProfileURL(profileBuilder.build().toString());
-
- return ret;
- }
-
-} \ No newline at end of file