public static UserRegistry getRegistry(HttpSession session) throws RegistryException { if (session == null) { return org.wso2.carbon.registry.common.utils.CommonUtil.getUserRegistry(registryService); } return org.wso2.carbon.registry.common.utils.CommonUtil.getUserRegistry( registryService, session); } }
protected void addErrorMessage(HttpServletRequest request, String msg) { CommonUtil.addErrorMessage(request, msg); } }
protected void sendErrorContent(HttpServletResponse response, String msg) { CommonUtil.sendErrorContent(response, msg); }
createdDateTime.setTime(child.getCreatedTime()); resourceData.setCreatedOn(createdDateTime); CommonUtil.populateAverageStars(resourceData); } else { resourceData.setPutAllowed( UserUtil.isPutAllowed(registry.getUserName(), path, registry)); resourceData.setDeleteAllowed( UserUtil.isDeleteAllowed(registry.getUserName(), path, registry)); resourceData.setGetAllowed( UserUtil.isGetAllowed(registry.getUserName(), path, registry));
public String getFormattedCreatedOn() { return CommonUtil.formatDate(createdOn.getTime()); }
public void updateTextContent(String resourcePath, String contentText,String updateOverride,String resourceVersion) throws Exception { try { MetadataBean metadataBean = stub.getMetadata(resourcePath); if(CommonUtil.isLatestVersion(resourceVersion, metadataBean.getResourceVersion()) || updateOverride.equals("true")){ stub.updateTextContent(resourcePath, contentText); }else{ throw new RegistryException("Another user has already modified this resource"); } } catch (Exception e) { String msg = "Failed to update text content of the resource " + resourcePath + ". " + e.getMessage(); log.error(msg, e); throw e; } }
public byte[] getReportBytes(ReportConfigurationBean configuration) throws Exception { return Utils.getReportContentStream( configuration.getReportClass(), configuration.getTemplate(), configuration.getType(), CommonUtil.attributeArrayToMap( configuration.getAttributes()), getRootRegistry()).toByteArray(); }
private String checkRetentionLock(Registry registry, String path, String retentionProperty) throws RegistryException { if (!registry.resourceExists(path)) { return null; } Resource existingResource = registry.get(path); if (CurrentSession.getUser() != null && !CurrentSession.getUser().equals( existingResource.getProperty(CommonConstants.RETENTION_USERNAME_PROP_NAME))) { if (Boolean.parseBoolean(existingResource.getProperty(retentionProperty))) { Date fromDate = CommonUtil.computeDate(existingResource.getProperty( CommonConstants.RETENTION_FROM_DATE_PROP_NAME)); Date toDate = CommonUtil.computeDate(existingResource.getProperty( CommonConstants.RETENTION_TO_DATE_PROP_NAME)); Date now = new Date(); if (now.compareTo(fromDate) > 0 && now.compareTo(toDate) < 0) { //Resource is locked, return the owner's username return existingResource.getProperty(CommonConstants.RETENTION_USERNAME_PROP_NAME); } } } return null; } }
public ContentBean getContent(HttpServletRequest request) throws Exception { String path = RegistryUtil.getPath(request); ContentBean bean = null; try { bean = stub.getContentBean(path); } catch (Exception e) { String msg = "Failed to get content from the resource service. " + e.getMessage(); log.error(msg, e); throw e; } return bean; }
public void setSessionResourcePath(String resourcePath) throws Exception { RegistryUtil.setSessionResourcePath(resourcePath); }
public String getSessionResourcePath() throws Exception { return RegistryUtil.getSessionResourcePath(); }
/** * Returns the resource path, which should be used to generate UIs. This will be set by the * metadata UI, when it is loading. So all other UIs in the resources page should load after * that. * * @param request this is used to get the current path set by the metadata UI. * @return current resource path */ public static String getPath(HttpServletRequest request) { String path = request.getParameter("path"); if (path == null || "".equals(path)) { path = (String) request.getAttribute("path"); } if (path != null) { path = sanitizeHTML(path); } return path; }
public Subscription getSubscription(String id) { try { if (id != null && id.contains(";version:")) { log.warn( "Versioned resources cannot have subscriptions, instead returns the subscription from the actual resource"); return EventingDataHolder.getInstance().getRegistryEventBrokerService() .getSubscription(RegistryUtil.getResourcePathFromVersionPath(id)); } else { return EventingDataHolder.getInstance().getRegistryEventBrokerService().getSubscription(id); } } catch (EventBrokerException e) { log.error("Unable to get subscription for given id: " + id, e); return null; } }
public boolean withdrawVote(String imagePath) { try { CommonUtil.getUserRegistry(Utils.getRegistryService()).removeAssociation(DEFAULT_SHUTTERBUG_HOME + RegistryConstants.PATH_SEPARATOR + VOTE_PATH, imagePath, ASSOCIATION_TYPE_VOTED); return true; } catch (Exception e) { log.error("Failed to withdraw vote", e); } return false; }
public PermissionBean getPermissions(HttpServletRequest request) throws Exception { String path = RegistryUtil.getPath(request); PermissionBean bean; try { bean = stub.getPermissions(path); } catch (Exception e) { String msg = "Failed to get permissions of the resource " + path + ". " + e.getMessage(); log.error(msg, e); throw e; } return bean; }
public MetadataBean getMetadata(String path) throws Exception { RegistryUtil.setSessionResourcePath(path); UserRegistry registry = (UserRegistry)getRootRegistry(); return MetadataPopulator.populate(path, registry); }
public boolean vote(String imagePath) { try { CommonUtil.getUserRegistry(Utils.getRegistryService()).addAssociation(DEFAULT_SHUTTERBUG_HOME + RegistryConstants.PATH_SEPARATOR + VOTE_PATH, imagePath, ASSOCIATION_TYPE_VOTED); return true; } catch (Exception e) { log.error("Failed to vote", e); } return false; }
public MetadataBean getMetadata(HttpServletRequest request) throws Exception { String path = RegistryUtil.getPath(request); if (path == null) { path = getSessionResourcePath(); if (path == null) { path = RegistryConstants.ROOT_PATH; } request.setAttribute("path", path); } MetadataBean bean = null; try { bean = stub.getMetadata(path); } catch (Exception e) { String msg = "Failed to get resource metadata from the resource service. " + e.getMessage(); log.error(msg, e); throw e; } return bean; }
public static UserRegistry getUserRegistry(RegistryService registryService) throws RegistryException { MessageContext messageContext = MessageContext.getCurrentMessageContext(); if (messageContext == null) { String msg = "Could not get the user's Registry session. Message context not found."; log.error(msg); throw new RegistryException(msg); } HttpServletRequest request = (HttpServletRequest) messageContext.getProperty("transport.http.servletRequest"); return getUserRegistry(registryService, request); }
public static String getCurrentUserID() throws Exception { Registry registry = getRegistryService().getSystemRegistry(); Resource shutterbugCollection = registry.get(DEFAULT_SHUTTERBUG_HOME); UserRegistry userRegistry = CommonUtil.getUserRegistry(Utils.getRegistryService()); String tenantUser = TENANT_USER_PREFIX + userRegistry.getTenantId() + "." + userRegistry.getUserName(); return shutterbugCollection.getProperty(tenantUser); }