Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions server/src/main/java/com/cloud/api/ApiResponseHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,15 @@ public class ApiResponseHelper implements ResponseGenerator {
@Inject
ResourceIconManager resourceIconManager;

public static String getPrettyDomainPath(String path) {
if (path == null) {
return null;
}
StringBuilder domainPath = new StringBuilder("ROOT");
(domainPath.append(path)).deleteCharAt(domainPath.length() - 1);
return domainPath.toString();
}

@Override
public UserResponse createUserResponse(User user) {
UserAccountJoinVO vUser = ApiDBUtils.newUserView(user);
Expand Down Expand Up @@ -567,9 +576,7 @@ public DomainResponse createDomainResponse(Domain domain) {
if (parentDomain != null) {
domainResponse.setParentDomainId(parentDomain.getUuid());
}
StringBuilder domainPath = new StringBuilder("ROOT");
(domainPath.append(domain.getPath())).deleteCharAt(domainPath.length() - 1);
domainResponse.setPath(domainPath.toString());
domainResponse.setPath(getPrettyDomainPath(domain.getPath()));
if (domain.getParent() != null) {
domainResponse.setParentDomainName(ApiDBUtils.findDomainById(domain.getParent()).getName());
}
Expand Down Expand Up @@ -2761,10 +2768,7 @@ public NetworkResponse createNetworkResponse(ResponseView view, Network network)
Domain domain = ApiDBUtils.findDomainById(domainNetworkDetails.first());
if (domain != null) {
response.setDomainId(domain.getUuid());

StringBuilder domainPath = new StringBuilder("ROOT");
(domainPath.append(domain.getPath())).deleteCharAt(domainPath.length() - 1);
response.setDomainPath(domainPath.toString());
response.setDomainPath(getPrettyDomainPath(domain.getPath()));
}
}
response.setSubdomainAccess(domainNetworkDetails.second());
Expand Down Expand Up @@ -3049,7 +3053,7 @@ private void populateOwner(ControlledEntityResponse response, ControlledEntity o
Domain domain = ApiDBUtils.findDomainById(object.getDomainId());
response.setDomainId(domain.getUuid());
response.setDomainName(domain.getName());
response.setDomainPath(domain.getPath());
response.setDomainPath(getPrettyDomainPath(domain.getPath()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shall we keep the same in the next methods or are these covered some how populateOwner(ControlledViewEntityResponse response, ControlledEntity object)
populateDomain(ControlledEntityResponse response, long domainId)
createUsageResponse(Usage usageRecord, Map<String, Set> resourceTagResponseMap, boolean oldFormat)
createAffinityGroupResponse(AffinityGroup group)
populateDomainFieldsOnConsoleSessionResponse()
createVMSnapshotResponse()
?

}

private void populateOwner(ControlledViewEntityResponse response, ControlledEntity object) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.apache.cloudstack.api.response.UserResponse;

import com.cloud.api.ApiDBUtils;
import com.cloud.api.ApiResponseHelper;
import com.cloud.api.query.ViewResponseHelper;
import com.cloud.api.query.vo.AccountJoinVO;
import com.cloud.api.query.vo.UserAccountJoinVO;
Expand Down Expand Up @@ -74,9 +75,7 @@ public AccountResponse newAccountResponse(ResponseView view, EnumSet<DomainDetai
accountResponse.setAccountType(account.getType().ordinal());
accountResponse.setDomainId(account.getDomainUuid());
accountResponse.setDomainName(account.getDomainName());
StringBuilder domainPath = new StringBuilder("ROOT");
(domainPath.append(account.getDomainPath())).deleteCharAt(domainPath.length() - 1);
accountResponse.setDomainPath(domainPath.toString());
accountResponse.setDomainPath(ApiResponseHelper.getPrettyDomainPath(account.getDomainPath()));
accountResponse.setState(account.getState().toString());
accountResponse.setCreated(account.getCreated());
accountResponse.setNetworkDomain(account.getNetworkDomain());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.cloudstack.api.response.AsyncJobResponse;
import org.apache.cloudstack.framework.jobs.AsyncJob;

import com.cloud.api.ApiResponseHelper;
import com.cloud.api.ApiSerializerHelper;
import com.cloud.api.SerializationContext;
import com.cloud.api.query.vo.AsyncJobJoinVO;
Expand Down Expand Up @@ -60,9 +61,7 @@ public AsyncJobResponse newAsyncJobResponse(final AsyncJobJoinVO job) {
jobResponse.setAccountId(job.getAccountUuid());
jobResponse.setAccount(job.getAccountName());
jobResponse.setDomainId(job.getDomainUuid());
StringBuilder domainPath = new StringBuilder("ROOT");
(domainPath.append(job.getDomainPath())).deleteCharAt(domainPath.length() - 1);
jobResponse.setDomainPath(domainPath.toString());
jobResponse.setDomainPath(ApiResponseHelper.getPrettyDomainPath(job.getDomainPath()));
jobResponse.setUserId(job.getUserUuid());
jobResponse.setCmd(job.getCmd());
jobResponse.setCreated(job.getCreated());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.List;


import com.cloud.api.ApiResponseHelper;
import com.cloud.configuration.Resource;
import com.cloud.user.AccountManager;
import org.apache.cloudstack.annotation.AnnotationService;
Expand Down Expand Up @@ -79,9 +80,7 @@ public DomainResponse newDomainResponse(ResponseView view, EnumSet<DomainDetails
if (domain.getParentUuid() != null) {
domainResponse.setParentDomainId(domain.getParentUuid());
}
StringBuilder domainPath = new StringBuilder("ROOT");
(domainPath.append(domain.getPath())).deleteCharAt(domainPath.length() - 1);
domainResponse.setPath(domainPath.toString());
domainResponse.setPath(ApiResponseHelper.getPrettyDomainPath(domain.getPath()));
if (domain.getParent() != null) {
domainResponse.setParentDomainName(domain.getParentName());
}
Expand Down
Loading