Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make profile REST API provide same information then XML API
Browse files Browse the repository at this point in the history
Current profile REST API misses the information: visible, enable and
enableBy. These are needed by IPA to improve the UI.

Additionally, a filter for visible and enable has been added.

Resolve RHCS-4375
fmarco76 committed Sep 26, 2023
1 parent 02a77e4 commit 7a933c0
Showing 3 changed files with 75 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -110,7 +110,7 @@ public ProfileService() {
}

@Override
public Response listProfiles(Integer start, Integer size) {
public Response listProfiles(Integer start, Integer size, Boolean visible, Boolean enable) {

start = start == null ? 0 : start;
size = size == null ? DEFAULT_SIZE : size;
@@ -136,13 +136,21 @@ public Response listProfiles(Integer start, Integer size) {
Enumeration<String> e = ps.getProfileIds();
if (e == null) return createOKResponse(infos);

if (visibleOnly && visible != null && !visible.booleanValue()) {
return createOKResponse(infos);
}

// store non-null results in a list
List<ProfileDataInfo> results = new ArrayList<>();
while (e.hasMoreElements()) {
try {
String id = e.nextElement();
ProfileDataInfo info = createProfileDataInfo(id, visibleOnly, uriInfo, getLocale(headers));
if (info == null) continue;
if (visible != null && info.getProfileVisible() != null && !info.getProfileVisible().equals(visible))
continue;
if (enable != null && info.getProfileEnable() != null && !info.getProfileEnable().equals(enable))
continue;
results.add(info);
} catch (EBaseException ex) {
continue;
@@ -383,6 +391,11 @@ public static ProfileDataInfo createProfileDataInfo(String profileId, boolean vi
ret.setProfileName(profile.getName(locale));
ret.setProfileDescription(profile.getDescription(locale));

if (!visibleOnly) {
ret.setProfileVisible(Boolean.valueOf(profile.isVisible()));
ret.setProfileEnable(Boolean.valueOf(profile.isEnable()));
ret.setProfileEnableBy(profile.getApprovedBy());
}
UriBuilder profileBuilder = uriInfo.getBaseUriBuilder();
URI uri = profileBuilder.path(ProfileResource.class).path("{id}").
build(profileId);
Original file line number Diff line number Diff line change
@@ -56,6 +56,12 @@ public class ProfileDataInfo implements JSONSerializer {

protected String profileDescription;

protected Boolean profileVisible;

protected Boolean profileEnable;

protected String profileEnableBy;

public ProfileDataInfo() {
}

@@ -100,6 +106,31 @@ public void setProfileDescription(String profileDescription) {
this.profileDescription = profileDescription;
}


public Boolean getProfileVisible() {
return profileVisible;
}

public void setProfileVisible(Boolean profileVisible) {
this.profileVisible = profileVisible;
}

public Boolean getProfileEnable() {
return profileEnable;
}

public void setProfileEnable(Boolean profileEnable) {
this.profileEnable = profileEnable;
}

public String getProfileEnableBy() {
return profileEnableBy;
}

public void setProfileEnableBy(String profileEnableBy) {
this.profileEnableBy = profileEnableBy;
}

@Override
public int hashCode() {
return Objects.hash(profileDescription, profileId, profileName, profileURL);
@@ -143,6 +174,21 @@ public Element toDOM(Document document) {
profileDescriptionElement.appendChild(document.createTextNode(profileDescription));
profileDataInfoElement.appendChild(profileDescriptionElement);
}
if (profileVisible != null) {
Element profileVisibleElement = document.createElement("profileVisible");
profileVisibleElement.appendChild(document.createTextNode(profileVisible.toString()));
profileDataInfoElement.appendChild(profileVisibleElement);
}
if (profileEnable != null) {
Element profileEnableElement = document.createElement("profileEnable");
profileEnableElement.appendChild(document.createTextNode(profileEnable.toString()));
profileDataInfoElement.appendChild(profileEnableElement);
}
if (profileEnableBy != null) {
Element profileEnableByElement = document.createElement("profileEnableBy");
profileEnableByElement.appendChild(document.createTextNode(profileEnableBy));
profileDataInfoElement.appendChild(profileEnableByElement);
}
return profileDataInfoElement;
}

@@ -166,6 +212,18 @@ public static ProfileDataInfo fromDOM(Element profileDataInfoElement) {
if (profileDescriptionList.getLength() > 0) {
profileDataInfo.setProfileDescription(profileDescriptionList.item(0).getTextContent());
}
NodeList profileVisibleList = profileDataInfoElement.getElementsByTagName("profileVisible");
if (profileVisibleList.getLength() > 0) {
profileDataInfo.setProfileVisible(Boolean.valueOf(profileVisibleList.item(0).getTextContent()));
}
NodeList profileEnableList = profileDataInfoElement.getElementsByTagName("profileEnable");
if (profileEnableList.getLength() > 0) {
profileDataInfo.setProfileEnable(Boolean.valueOf(profileEnableList.item(0).getTextContent()));
}
NodeList profileEnableByList = profileDataInfoElement.getElementsByTagName("profileEnableBy");
if (profileEnableByList.getLength() > 0) {
profileDataInfo.setProfileEnableBy(profileEnableByList.item(0).getTextContent());
}
return profileDataInfo;
}

Original file line number Diff line number Diff line change
@@ -20,7 +20,9 @@ public interface ProfileResource {
@ACLMapping("profiles.list")
public Response listProfiles(
@QueryParam("start") Integer start,
@QueryParam("size") Integer size);
@QueryParam("size") Integer size,
@QueryParam("visible") Boolean visible,
@QueryParam("enable") Boolean enable);

@GET
@Path("{id}")

0 comments on commit 7a933c0

Please sign in to comment.