HttpServletResponse response) throws IOException {
IUserInstance ui = userInstanceManager.getUserInstance(request);
IPerson per = getPerson(ui, response);
UserPreferencesManager upm = (UserPreferencesManager) ui.getPreferencesManager();
IUserLayoutManager ulm = upm.getUserLayoutManager();
// Get the fragment owner's name from the request and construct
// an IPerson object representing that user
String fragmentOwnerName = request.getParameter("sourceID");
if (StringUtils.isBlank(fragmentOwnerName)) {
log.warn("Attempted to subscribe to tab with null owner ID");
response.sendError(HttpServletResponse.SC_BAD_REQUEST);
return null;
}
RestrictedPerson fragmentOwner = PersonFactory.createRestrictedPerson();
fragmentOwner.setUserName(fragmentOwnerName);
// Mark the currently-authenticated user as subscribed to this fragment.
// If an inactivated fragment registration already exists, update it
// as an active subscription. Otherwise, create a new fragment
// subscription.
IUserFragmentSubscription userFragmentInfo = userFragmentInfoDao
.getUserFragmentInfo(per, fragmentOwner);
if (userFragmentInfo == null) {
userFragmentInfo = userFragmentInfoDao.createUserFragmentInfo(per,
fragmentOwner);
} else {
userFragmentInfo.setActive(true);
userFragmentInfoDao.updateUserFragmentInfo(userFragmentInfo);
}
try {
// reload user layout and stylesheet to incorporate new DLM fragment
ulm.loadUserLayout(true);
// get the target node this new tab should be moved after
String destinationId = request.getParameter("elementID");
// get the user layout for the currently-authenticated user
int uid = userIdentityStore.getPortalUID(fragmentOwner, false);
final DistributedUserLayout userLayout = userLayoutStore.getUserLayout(per, upm.getUserProfile());
Document layoutDocument = userLayout.getLayout();
// attempt to find the new subscribed tab in the layout so we can
// move it
StringBuilder expression = new StringBuilder("//folder[@type='root']/folder[starts-with(@ID,'")