public String getFormattedCreatedOn() { return CommonUtil.formatDate(createdOn.getTime()); }
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); } }
if (attributes != null && attributes.length() > 0) { Map<String, String> attributeMap = CommonUtil.attributeArrayToMap(bean.getAttributes()); attributes = attributes.substring(0, attributes.length() - 1); String[] attributeStrings = attributes.split("\\^"); attributeMap.put(pair[0].substring("attribute".length()), pair[1]); bean.setAttributes(CommonUtil.mapToAttributeArray(attributeMap));
if (getServiceOMElement(requestContext.getResource()) != null) { currentParameterMap.put(requestContext.getResource().getPath(), org.wso2.carbon.registry.common.utils.CommonUtil.getServiceVersion( getServiceOMElement(requestContext.getResource()))); return true; if (getServiceOMElement(requestContext.getResource()) != null) { currentParameterMap.put(requestContext.getResource().getPath(), org.wso2.carbon.registry.common.utils.CommonUtil.getServiceVersion( getServiceOMElement(requestContext.getResource()))); if (requestContext.getResource().getPath().equals(association.getSourcePath())) { currentParameterMap.put(association.getDestinationPath(), org.wso2.carbon.registry.common.utils.CommonUtil.getServiceVersion( getServiceOMElement(requestContext.getResource())));
query.setAuthorName(authorName); query.setUpdaterName(updaterName); query.setCreatedAfter(CommonUtil.computeDate(createdAfter)); query.setCreatedBefore(CommonUtil.computeDate(createdBefore)); query.setUpdatedAfter(CommonUtil.computeDate(updatedAfter)); query.setUpdatedBefore(CommonUtil.computeDate(updatedBefore)); query.setCommentWords(commentWords); query.setTags(tags); createdDateTime.setTime(child.getCreatedTime()); resourceData.setCreatedOn(createdDateTime); CommonUtil.populateAverageStars(resourceData);
public byte[] getReportBytes(ReportConfigurationBean configuration) throws Exception { return Utils.getReportContentStream( configuration.getReportClass(), configuration.getTemplate(), configuration.getType(), CommonUtil.attributeArrayToMap( configuration.getAttributes()), getRootRegistry()).toByteArray(); }
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 WorkListConfig() { String configPath = CarbonUtils.getRegistryXMLPath(); if (configPath != null) { File registryXML = new File(configPath); if (registryXML.exists()) { try { FileInputStream fileInputStream = new FileInputStream(registryXML); StAXOMBuilder builder = new StAXOMBuilder( CarbonUtils.replaceSystemVariablesInXml(fileInputStream)); OMElement configElement = builder.getDocumentElement(); SecretResolver secretResolver = SecretResolverFactory.create(configElement, false); OMElement workList = configElement.getFirstChildWithName(new QName("workList")); if (workList != null) { username = workList.getFirstChildWithName(new QName("username")).getText(); password = CommonUtil.getResolvedPassword(secretResolver,"workList", workList.getFirstChildWithName(new QName("password")).getText()); serverURL = workList.getAttributeValue(new QName("serverURL")); remote = workList.getAttributeValue(new QName("remote")); } } catch (XMLStreamException e) { log.error("Unable to parse registry.xml", e); } catch (IOException e) { log.error("Unable to read registry.xml", e); } catch (CarbonException e) { log.error("An error occurred during system variable replacement", e); } } } }
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; } }
private ReportConfigurationBean getConfigurationBean(String path) throws RegistryException, CryptoException, TaskException { Registry registry = getConfigSystemRegistry(); Resource resource = registry.get(path); ReportConfigurationBean bean = new ReportConfigurationBean(); String name = RegistryUtils.getResourceName(path); bean.setName(name); bean.setCronExpression(resource.getProperty("cronExpression")); TaskManager taskManager = ReportingServiceComponent.getTaskManager( ((UserRegistry) getRootRegistry()).getTenantId()); bean.setScheduled(taskManager.isTaskScheduled(name)); bean.setReportClass(resource.getProperty("class")); bean.setResourcePath(resource.getProperty("resourcePath")); bean.setTemplate(resource.getProperty("template")); bean.setType(resource.getProperty("type")); bean.setUsername(resource.getProperty("registry.username")); bean.setTenantId(Integer.parseInt(resource.getProperty("registry.tenantId"))); Map<String, String> attributes = new HashMap<String, String>(); Properties props = resource.getProperties(); for (Object key : props.keySet()) { String propKey = (String) key; if (propKey.startsWith("attribute.")) { attributes.put(propKey.substring("attribute.".length()), resource.getProperty(propKey)); } } bean.setAttributes(CommonUtil.mapToAttributeArray(attributes)); return bean; }
if (getServiceOMElement(requestContext.getResource()) != null) { currentParameterMap.put(requestContext.getResource().getPath(), org.wso2.carbon.registry.common.utils.CommonUtil.getServiceVersion( getServiceOMElement(requestContext.getResource()))); return true; if (getServiceOMElement(requestContext.getResource()) != null) { currentParameterMap.put(requestContext.getResource().getPath(), org.wso2.carbon.registry.common.utils.CommonUtil.getServiceVersion( getServiceOMElement(requestContext.getResource()))); if (requestContext.getResource().getPath().equals(association.getSourcePath())) { currentParameterMap.put(association.getDestinationPath(), org.wso2.carbon.registry.common.utils.CommonUtil.getServiceVersion( getServiceOMElement(requestContext.getResource())));
public void scheduleReport(ReportConfigurationBean configuration) throws Exception { HashMap<String, String> propertyMap = new HashMap<String, String>( CommonUtil.attributeArrayToMap(configuration.getAttributes())); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); propertyMap.put("reporting.registry.username", username); propertyMap.put("reporting.registry.tenantId", String.valueOf(tenantId)); propertyMap.put("reporting.type", configuration.getType()); propertyMap.put("reporting.class", configuration.getReportClass()); propertyMap.put("reporting.template", configuration.getTemplate()); propertyMap.put("reporting.resource.path", configuration.getResourcePath()); String clazz = ReportingTask.class.getName(); TaskManager taskManager = ReportingServiceComponent.getTaskManager(tenantId); taskManager.registerTask(new TaskInfo(configuration.getName(), clazz, propertyMap, new TaskInfo.TriggerInfo(configuration.getCronExpression()))); taskManager.rescheduleTask(configuration.getName()); // Re-adding full configuration properties to report path -REGISTRY-1017 saveReport(configuration); }
public boolean updateLifeCycle(HttpServletRequest request) throws Exception { String lifecycleName = request.getParameter("lifecycleName"); String updateOverride = request.getParameter("updateOverride"); if (lifecycleName == null) { lifecycleName = ""; } String payload = request.getParameter("payload"); boolean output; try { if (!stub.parseConfiguration(payload)) { return false; } String latestVersion = stub.getLifecycleConfigurationVersion(lifecycleName); if(updateOverride.equals("true") || CommonUtil.isLatestVersion((String) request.getSession().getAttribute("resourceVersion"),latestVersion)){ output = stub.updateLifecycle(lifecycleName, payload); } else{ throw new Exception("Lifecycle resource has already modified "); } } catch (Exception e) { if (e instanceof RegistryException) { return false; } else { log.error(e); throw e; } } return output; }
executorService.scheduleWithFixedDelay(new SCMUpdateTask(directory, checkOutURL, checkInURL, readOnly, externalContentHandler, username, CommonUtil.getResolvedPassword(secretResolver,"scm",password)), 0, updateFrequency, TimeUnit.MINUTES);
activities.add(log.getUserName() + " has added the resource " + log.getResourcePath() + " at " + CommonUtil.formatDate(log.getDate()) + "."); break; case LogEntry.UPDATE: activities.add(log.getUserName() + " has updated the resource " + log.getResourcePath() + " at " + CommonUtil.formatDate(log.getDate()) + "."); break; case LogEntry.DELETE_RESOURCE: activities.add(log.getUserName() + " has deleted the resource " + log.getResourcePath() + " at " + CommonUtil.formatDate(log.getDate()) + "."); break; case LogEntry.COMMENT: activities.add(log.getUserName() + " has commented on the resource " + log.getResourcePath() + " at " + CommonUtil.formatDate(log.getDate()) + "."); break; case LogEntry.DELETE_COMMENT: activities.add(log.getUserName() + " has deleted a comment on the " + "resource " + log.getResourcePath() + " at " + CommonUtil.formatDate(log.getDate()) + "."); break; case LogEntry.TAG: activities.add(log.getUserName() + " has tagged the resource " + log.getResourcePath() + " at " + CommonUtil.formatDate(log.getDate()) + "."); break;
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; }
CommonUtil.getEndpointEntries(serviceInfoElement)); CommonUtil.setServiceVersion(oldServiceInfoElement, org.wso2.carbon.registry.common.utils.CommonUtil.getServiceVersion( serviceInfoElement)); serviceInfoElement = oldServiceInfoElement;
CommonUtil.attributeArrayToMap(configuration.getAttributes()).entrySet()) { resource.setProperty("attribute." + e.getKey(), e.getValue());
if(logEntry.getUserName().equals(Username)){ if (logEntry.getAction() == LogEntry.ADD) { String entry = Boolean.toString(resourceExists(registry, logEntry)) + "|" + logEntry.getUserName() + "|" + logEntry.getUserName() + "|" + " has added the resource " + "|" + logEntry.getResourcePath() + "|" + logEntry.getResourcePath() + "|" + " " + CommonUtil.formatDate(logEntry.getDate()) + "."; list.add(entry); String entry = Boolean.toString(resourceExists(registry, logEntry)) + "|" + logEntry.getUserName() + "|" + logEntry.getUserName() + "|" + " has updated the resource " + "|" + logEntry.getResourcePath() + "|" + logEntry.getResourcePath() + "|" + " " + CommonUtil.formatDate(logEntry.getDate()) + "."; list.add(entry); String entry = Boolean.toString(resourceExists(registry, logEntry)) + "|" + logEntry.getUserName() + "|" + logEntry.getUserName() + "|" + " has deleted the resource " + "|" + logEntry.getResourcePath() + "|" + logEntry.getResourcePath() + "|" + " " + CommonUtil.formatDate(logEntry.getDate()) + "."; list.add(entry); String entry = Boolean.toString(resourceExists(registry, logEntry)) + "|" + logEntry.getUserName() + "|" + logEntry.getUserName() + "|" + " has commented on resource " + "|" + logEntry.getResourcePath() + "|" + logEntry.getResourcePath() + "|" + " " + CommonUtil.formatDate(logEntry.getDate()) + " with the following comment." + "|" + logEntry.getActionData(); list.add(entry); String entry = Boolean.toString(resourceExists(registry, logEntry)) + "|" + logEntry.getUserName() + "|" + logEntry.getUserName() + "|" + " has deleted the comment '" + logEntry.getActionData() + "' on the resource " + "|" + logEntry.getResourcePath() + "|" + logEntry.getResourcePath() + "|" + " " + CommonUtil.formatDate(logEntry.getDate()) + "."; list.add(entry); String entry = Boolean.toString(resourceExists(registry, logEntry)) + "|" + logEntry.getUserName() + "|" + logEntry.getUserName() + "|" + " has tagged the resource " + "|" + logEntry.getResourcePath() + "|" + logEntry.getResourcePath() + "|" + " with tag '" + logEntry.getActionData() + "' " + CommonUtil.formatDate(logEntry.getDate()) + "."; list.add(entry); String entry = Boolean.toString(resourceExists(registry, logEntry)) + "|" + logEntry.getUserName() + "|" + logEntry.getUserName() + "|" + " has removed the tag '" + logEntry.getActionData() + "' on the resource " + "|" + logEntry.getResourcePath() + "|" + logEntry.getResourcePath() + "|" + " " + CommonUtil.formatDate(logEntry.getDate()) + "."; list.add(entry); String entry = Boolean.toString(resourceExists(registry, logEntry)) + "|" + logEntry.getUserName() + "|" + logEntry.getUserName() + "|" + " has rated the resource " + "|" + logEntry.getResourcePath() + "|" + logEntry.getResourcePath() + "|" + " with rating " + logEntry.getActionData() + " " + CommonUtil.formatDate(logEntry.getDate()) + "."; list.add(entry); String[] actionData = logEntry.getActionData().split(";"); if (actionData != null && actionData.length >= 2) { String entry = Boolean.toString(resourceExists(registry, logEntry)) + "|" + logEntry.getUserName() + "|" + logEntry.getUserName() + "|" + " has added an association of type " + actionData[0] + " from the resource " + "|" + logEntry.getResourcePath() + "|" + logEntry.getResourcePath() + "|" + " to the resource " + actionData[1] + " " + CommonUtil.formatDate(logEntry.getDate()) + ".";
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; }