try {
BIObject obj = getRequiredBIObject();
boolean documentFound = false;
boolean canSeeDocument = false;
UserProfile profile = (UserProfile) getUserProfile();
documentFound = obj != null;
if (obj != null) {
canSeeDocument = ObjectsAccessVerifier.canSee(obj, profile);
}
HttpServletRequest httpRequest = getHttpRequest();
MessageBuilder m = new MessageBuilder();
Locale locale = m.getLocale(httpRequest);
JSONObject result = new JSONObject();
if (!documentFound) {
result.put("documentFound", false);
} else {
result.put("documentFound", true);
if (!canSeeDocument) {
result.put("canSeeDocument", false);
} else {
JSONObject document = (JSONObject) SerializerFactory.getSerializer("application/json").serialize( obj ,locale);
result.put("document", document);
result.put("canSeeDocument", true);
SubObject subObject = getRequiredSubObject(obj);
if (subObject != null) {
if (profile.isAbleToExecuteAction(SpagoBIConstants.DOCUMENT_MANAGEMENT_ADMIN) ||
(subObject.getIsPublic().booleanValue() || subObject.getOwner().equals(profile.getUserId()))) {
JSONObject subObjectJSON = (JSONObject) SerializerFactory.getSerializer("application/json").serialize( subObject ,locale);
result.put("subobject", subObjectJSON);
} else {
logger.warn("User cannot see subobject [" + subObject.getName() + "] of document with label [" + obj.getLabel() + "].");
result.put("canSeeSubobject", false);