Java Code Examples for org.wso2.carbon.registry.core.Resource#getContent()
The following examples show how to use
org.wso2.carbon.registry.core.Resource#getContent() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProviderMigrationClient.java From product-es with Apache License 2.0 | 5 votes |
private void migrateProvider(Collection root, Registry registry) throws RegistryException, SAXException, TransformerException, ParserConfigurationException, IOException { String[] childrenPaths = root.getChildren(); for (String child : childrenPaths) { Resource childResource = registry.get(child); if (childResource instanceof Collection) { migrateProvider((Collection) childResource, registry); } else { String path = childResource.getPath(); byte[] configContent = (byte[]) childResource.getContent(); String contentString = RegistryUtils.decodeBytes(configContent); Document dom = stringToDocument(contentString); if (dom.getElementsByTagName(Constants.OVERVIEW).getLength() > 0) { Node overview = dom.getElementsByTagName(Constants.OVERVIEW).item(0); NodeList childrenList = overview.getChildNodes(); for (int j = 0; j < childrenList.getLength(); j++) { Node node = childrenList.item(j); if (Constants.PROVIDER.equals(node.getNodeName())) { overview.removeChild(node); } } String newContentString = documentToString(dom); byte[] newContentObject = RegistryUtils.encodeString(newContentString); childResource.setContent(newContentObject); registry.put(path, childResource); } } } }
Example 2
Source File: RegistryPolicyReader.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
/** * Reads PolicyDTO for given registry resource * * @param resource Registry resource * @return PolicyDTO * @throws EntitlementException throws, if fails */ private PolicyDTO readPolicy(Resource resource) throws EntitlementException { String policy = null; AbstractPolicy absPolicy = null; PolicyDTO dto = null; try { if (resource.getContent() == null) { throw new EntitlementException("Error while loading entitlement policy. Policy content is null"); } policy = new String((byte[]) resource.getContent(), Charset.forName("UTF-8")); absPolicy = PAPPolicyReader.getInstance(null).getPolicy(policy); dto = new PolicyDTO(); dto.setPolicyId(absPolicy.getId().toASCIIString()); dto.setPolicy(policy); String policyOrder = resource.getProperty("order"); if (policyOrder != null) { dto.setPolicyOrder(Integer.parseInt(policyOrder)); } else { dto.setPolicyOrder(0); } String policyActive = resource.getProperty("active"); if (policyActive != null) { dto.setActive(Boolean.parseBoolean(policyActive)); } PolicyAttributeBuilder policyAttributeBuilder = new PolicyAttributeBuilder(); dto.setAttributeDTOs(policyAttributeBuilder. getPolicyMetaDataFromRegistryProperties(resource.getProperties())); return dto; } catch (RegistryException e) { log.error("Error while loading entitlement policy", e); throw new EntitlementException("Error while loading entitlement policy", e); } }
Example 3
Source File: ProviderMigrationClient.java From product-es with Apache License 2.0 | 5 votes |
/** * This method checks whether there is a provider in the overview table. * @param rxtPath path of the rxt file * @param registry registry instance * @return boolean * @throws RegistryException * @throws IOException * @throws SAXException * @throws ParserConfigurationException * @throws XMLStreamException */ private boolean hasOverviewProviderElement(String rxtPath, Registry registry) throws RegistryException, IOException, SAXException, ParserConfigurationException, XMLStreamException { Resource artifactRxt = registry.get(rxtPath); byte[] rxtContent = (byte[]) artifactRxt.getContent(); String rxtContentString = RegistryUtils.decodeBytes(rxtContent); OMElement rxtContentOM = AXIOMUtil.stringToOM(rxtContentString); OMElement contentElement = rxtContentOM.getFirstChildWithName(new QName(Constants.CONTENT)); Iterator tableNodes = contentElement.getChildrenWithLocalName(Constants.TABLE); while (tableNodes.hasNext()) { OMElement tableOMElement = (OMElement) tableNodes.next(); if ("Overview".equals(tableOMElement.getAttributeValue(new QName(Constants.NAME)))) { Iterator fieldNodes = tableOMElement.getChildrenWithLocalName(Constants.FIELD); while (fieldNodes.hasNext()) { OMElement fieldElement = (OMElement) fieldNodes.next(); OMElement nameElement = fieldElement.getFirstChildWithName(new QName(Constants.NAME)); if (nameElement != null) { if ("Provider".equals(nameElement.getText())) { return true; } } } } } return false; }
Example 4
Source File: AbstractDAO.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
/** * Returns the first object in a registry path with a given property value. * * @param path registry path * @param propName name of the property to be matched * @param value value of the property to be matched * @return first objects matching the given property value in the given registry path * @throws IdentityException if an error occurs while reading the registry */ public T getFirstObjectWithPropertyValue(String path, String propName, String value) throws IdentityException { Resource resource = null; Map<String, String> params = null; Resource result = null; String[] paths = null; try { if (log.isErrorEnabled()) { log.debug("Retrieving first object from the registry path with property value " + path); } params = new HashMap<String, String>(); params.put("1", propName); params.put("2", value); result = registry.executeQuery(getCustomQuery(), params); paths = (String[]) result.getContent(); if (paths != null && paths.length > 0) { resource = registry.get(paths[0]); } } catch (RegistryException e) { String message = "Error while retrieving first object from the registry path with property value"; log.error(message, e); throw IdentityException.error(message, e); } return resourceToObject(resource); }
Example 5
Source File: MigrateData.java From product-es with Apache License 2.0 | 5 votes |
private void updateResource(Registry registry, String path) throws RegistryException { if (registry.resourceExists(path)) { Resource resource = registry.get(path); String content = new String((byte[]) resource.getContent()); if (content.contains(Constants.LOGIN_SCRIPT)) { content = content.replace(Constants.LOGIN_PERMISSION, ""); content = content.replace(Constants.PERMISSION_ACTION, ""); resource.setContent(content); registry.put(path, resource); } } }
Example 6
Source File: ProviderMigrationClient.java From product-es with Apache License 2.0 | 5 votes |
private String getStoragePath(String rxtPath, Registry registry) throws RegistryException, IOException, SAXException, ParserConfigurationException { Resource artifactRxt = registry.get(rxtPath); byte[] rxtContent = (byte[]) artifactRxt.getContent(); String rxtContentString = RegistryUtils.decodeBytes(rxtContent); Document dom = stringToDocument(rxtContentString); Node storagePath = dom.getElementsByTagName(Constants.STORAGE_PATH).item(0); return storagePath.getFirstChild().getNodeValue(); }
Example 7
Source File: RegistryPolicyReader.java From carbon-identity with Apache License 2.0 | 5 votes |
/** * Reads PolicyDTO for given registry resource * * @param resource Registry resource * @return PolicyDTO * @throws EntitlementException throws, if fails */ private PolicyDTO readPolicy(Resource resource) throws EntitlementException { String policy = null; AbstractPolicy absPolicy = null; PolicyDTO dto = null; try { if (resource.getContent() == null) { throw new EntitlementException("Error while loading entitlement policy. Policy content is null"); } policy = new String((byte[]) resource.getContent(), Charset.forName("UTF-8")); absPolicy = PAPPolicyReader.getInstance(null).getPolicy(policy); dto = new PolicyDTO(); dto.setPolicyId(absPolicy.getId().toASCIIString()); dto.setPolicy(policy); String policyOrder = resource.getProperty("order"); if (policyOrder != null) { dto.setPolicyOrder(Integer.parseInt(policyOrder)); } else { dto.setPolicyOrder(0); } String policyActive = resource.getProperty("active"); if (policyActive != null) { dto.setActive(Boolean.parseBoolean(policyActive)); } PolicyAttributeBuilder policyAttributeBuilder = new PolicyAttributeBuilder(); dto.setAttributeDTOs(policyAttributeBuilder. getPolicyMetaDataFromRegistryProperties(resource.getProperties())); return dto; } catch (RegistryException e) { log.error("Error while loading entitlement policy", e); throw new EntitlementException("Error while loading entitlement policy", e); } }
Example 8
Source File: ProviderMigrationClient.java From product-es with Apache License 2.0 | 5 votes |
private String getMediaType(String rxtPath, Registry registry) throws RegistryException, IOException, SAXException, ParserConfigurationException { Resource artifactRxt = registry.get(rxtPath); byte[] rxtContent = (byte[]) artifactRxt.getContent(); String rxtContentString = RegistryUtils.decodeBytes(rxtContent); Document dom = stringToDocument(rxtContentString); Element domElement = (Element) dom.getElementsByTagName(Constants.ARTIFACT_TYPE).item(0); return domElement.getAttribute(Constants.TYPE); }
Example 9
Source File: AbstractDAO.java From carbon-identity with Apache License 2.0 | 5 votes |
/** * @param path * @param propName * @param value * @return */ public T getFirstObjectWithPropertyValue(String path, String propName, String value) throws IdentityException { Resource resource = null; Map<String, String> params = null; Resource result = null; String[] paths = null; try { if (log.isErrorEnabled()) { log.debug("Retreving first object from the registry path with property value " + path); } params = new HashMap<String, String>(); params.put("1", propName); params.put("2", value); result = registry.executeQuery(getCustomQuery(), params); paths = (String[]) result.getContent(); if (paths != null && paths.length > 0) { resource = registry.get(paths[0]); } } catch (RegistryException e) { String message = "Error while retreving first object from the registry path with property value"; log.error(message, e); throw IdentityException.error(message, e); } return resourceToObject(resource); }
Example 10
Source File: PAPPolicyStoreReader.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
/** * @param policyId * @param finder * @return * @throws EntitlementException */ public synchronized AbstractPolicy readPolicy(String policyId, PolicyFinder finder) throws EntitlementException { Resource resource = store.getPolicy(policyId, PDPConstants.ENTITLEMENT_POLICY_PAP); if (resource != null) { try { String policy = new String((byte[]) resource.getContent(), Charset.forName("UTF-8")); return PAPPolicyReader.getInstance(null).getPolicy(policy); } catch (RegistryException e) { log.error("Error while parsing entitlement policy", e); throw new EntitlementException("Error while loading entitlement policy"); } } return null; }
Example 11
Source File: ProviderMigrationClient.java From product-es with Apache License 2.0 | 5 votes |
private boolean isContentArtifact(String rxtPath, Registry registry) throws RegistryException, IOException, SAXException, ParserConfigurationException { Resource artifactRxt = registry.get(rxtPath); byte[] rxtContent = (byte[]) artifactRxt.getContent(); String rxtContentString = RegistryUtils.decodeBytes(rxtContent); Document dom = stringToDocument(rxtContentString); Element domElement = (Element) dom.getElementsByTagName(Constants.ARTIFACT_TYPE).item(0); return domElement.hasAttribute(Constants.FILE_EXTENSION); }
Example 12
Source File: RegistryManager.java From attic-stratos with Apache License 2.0 | 5 votes |
private Object retrieve(String resourcePath) { try { Resource resource = registryService.get(resourcePath); return resource.getContent(); } catch (ResourceNotFoundException ignore) { // this means, we've never persisted info in registry return null; } catch (RegistryException e) { String msg = "Failed to retrieve data from registry."; log.error(msg, e); throw new AutoScalerException(msg, e); } }
Example 13
Source File: APIMRegistryServiceImpl.java From carbon-apimgt with Apache License 2.0 | 4 votes |
protected String getString(Resource resource) throws RegistryException { return new String((byte[]) resource.getContent(), Charset.defaultCharset()); }
Example 14
Source File: CarbonRepositoryUtils.java From carbon-commons with Apache License 2.0 | 4 votes |
/** * Loads the deployment synchronizer configuration from the configuration registry of the * specified tenant. * * @param tenantId Tenant ID * @return a DeploymentSynchronizerConfiguration object or null * @throws org.wso2.carbon.registry.core.exceptions.RegistryException if the registry cannot be accessed */ public static DeploymentSynchronizerConfiguration getDeploymentSyncConfigurationFromRegistry( int tenantId) throws RegistryException { UserRegistry localRepository = getLocalRepository(tenantId); if (!localRepository.resourceExists(DeploymentSynchronizerConstants.CARBON_REPOSITORY)) { return null; } Resource resource = localRepository.get(DeploymentSynchronizerConstants.CARBON_REPOSITORY); DeploymentSynchronizerConfiguration config = new DeploymentSynchronizerConfiguration(); String status = new String((byte[]) resource.getContent()); if ("enabled".equals(status)) { config.setEnabled(true); } config.setAutoCheckout(Boolean.valueOf(resource.getProperty( DeploymentSynchronizerConstants.AUTO_CHECKOUT_MODE))); config.setAutoCommit(Boolean.valueOf(resource.getProperty( DeploymentSynchronizerConstants.AUTO_COMMIT_MODE))); config.setPeriod(Long.valueOf(resource.getProperty( DeploymentSynchronizerConstants.AUTO_SYNC_PERIOD))); config.setUseEventing(Boolean.valueOf(resource.getProperty( DeploymentSynchronizerConstants.USE_EVENTING))); config.setRepositoryType(resource.getProperty( DeploymentSynchronizerConstants.REPOSITORY_TYPE)); ArtifactRepository repository = RepositoryReferenceHolder.getInstance().getRepositoryByType(config.getRepositoryType()); if (repository == null) { throw new RegistryException("No Repository found for type " + config.getRepositoryType()); } List<RepositoryConfigParameter> parameters = repository.getParameters(); //If repository specific configuration parameters are found. if (parameters != null) { //Find the 'value' of each parameter from the registry by parameter 'name' and attach to parameter for (RepositoryConfigParameter parameter : parameters) { parameter.setValue(resource.getProperty(parameter.getName())); } //Attach parameter list to config object. config.setRepositoryConfigParameters(parameters.toArray(new RepositoryConfigParameter[parameters.size()])); } resource.discard(); return config; }
Example 15
Source File: NewAPIVersionEmailNotifier.java From carbon-apimgt with Apache License 2.0 | 4 votes |
/** * Retrieves the message configurations from tenant-config.json and sets the notification properties to * NotificationDTO * * @param notificationDTO * @return NotificationDTO after setting meesage and title * @throws NotificationException */ public NotificationDTO loadMessageTemplate(NotificationDTO notificationDTO) throws NotificationException { APIIdentifier api = (APIIdentifier) notificationDTO.getProperties().get(NotifierConstants.API_KEY); APIIdentifier newApi = (APIIdentifier) notificationDTO.getProperties().get(NotifierConstants.NEW_API_KEY); String title = (String) notificationDTO.getProperty(NotifierConstants.TITLE_KEY); title = title.replaceAll("\\$1", newApi.getApiName()); title = title.replaceAll("\\$2", newApi.getVersion()); // Getting the message template from registry file String content = ""; try { String template = (String) notificationDTO.getProperty(NotifierConstants.TEMPLATE_KEY); int tenantId = notificationDTO.getTenantID(); Registry registry = getConfigSystemRegistry(tenantId); if (registry.resourceExists(template)) { if (log.isDebugEnabled()) { log.debug("Getting message template from registry resource : " + template); } Resource resource = registry.get(template); content = new String((byte[]) resource.getContent(), Charset.defaultCharset()); } else { content = template; } } catch (RegistryException e) { throw new NotificationException("Error while getting registry resource", e); } if (content != null && !content.isEmpty()) { content = content.replaceAll("\\$1", newApi.getApiName()); content = content.replaceAll("\\$2", newApi.getVersion()); content = content.replaceAll("\\$3", newApi.getProviderName()); content = content.replaceAll("\\$4", api.getApiName()); content = content.replaceAll("\\$5", api.getVersion()); } notificationDTO.setTitle(title); notificationDTO.setMessage(content); return notificationDTO; }
Example 16
Source File: APIEndpointPasswordRegistryHandler.java From carbon-apimgt with Apache License 2.0 | 4 votes |
/** * This method is called for a registry put operation * * @param requestContext - The request context * @throws RegistryException */ public void put(RequestContext requestContext) throws RegistryException { Resource resource = requestContext.getResource(); Object content = resource.getContent(); String resourceContent; if (content instanceof String) { resourceContent = (String) resource.getContent(); } else if (content instanceof byte[]) { resourceContent = RegistryUtils.decodeBytes((byte[]) resource.getContent()); } else { log.warn("The resource content is not of expected type"); return; } try { OMElement omElement = AXIOMUtil.stringToOM(resourceContent); Iterator mainChildIt = omElement.getChildren(); while (mainChildIt.hasNext()) { Object childObj = mainChildIt.next(); if ((childObj instanceof OMElement) && ((APIConstants.OVERVIEW_ELEMENT) .equals(((OMElement) childObj).getLocalName()))) { Iterator childIt = ((OMElement) childObj) .getChildrenWithLocalName(APIConstants.ENDPOINT_PASSWORD_ELEMENT); //There is only one ep-password, hence no iteration if (childIt.hasNext()) { OMElement child = (OMElement) childIt.next(); String pswd = child.getText(); //Password has been edited on put if (!"".equals(pswd) && !((APIConstants.DEFAULT_MODIFIED_ENDPOINT_PASSWORD).equals(pswd))) { resource.setProperty(APIConstants.REGISTRY_HIDDEN_ENDPOINT_PROPERTY, pswd); child.setText(pswd); } else if ((APIConstants.DEFAULT_MODIFIED_ENDPOINT_PASSWORD) .equals(pswd)) { //Password not being changed String actualPassword = resource .getProperty(APIConstants.REGISTRY_HIDDEN_ENDPOINT_PROPERTY); child.setText(actualPassword); } } } } resource.setContent(RegistryUtils.encodeString(omElement.toString())); requestContext.setResource(resource); log.debug("Modified API resource content with actual password before put operation"); } catch (XMLStreamException e) { log.error("There was an error in reading XML Stream during API update."); throw new RegistryException("There was an error updating the API resource.", e); } }
Example 17
Source File: AbstractDAO.java From carbon-identity with Apache License 2.0 | 4 votes |
/** * @param path * @param propName * @param value * @return */ public List<T> getAllObjectsWithPropertyValue(String path, String propName, String value) throws IdentityException { Resource query = null; List<T> retList = null; Map<String, String> params = null; Resource result = null; String[] paths = null; Resource resource = null; if (log.isErrorEnabled()) { log.debug("Retreving all objects from the registry path with property values " + path); } try { retList = new ArrayList<T>(); if (registry.resourceExists(CUSTOM_QUERY_GET_ALL_BY_PROP)) { //query = registry.get(CUSTOM_QUERY_GET_ALL_BY_PROP); } else { query = registry.newResource(); query.setContent(SQL_GET_ALL_BY_PROP); query.setMediaType(RegistryConstants.SQL_QUERY_MEDIA_TYPE); query.addProperty(RegistryConstants.RESULT_TYPE_PROPERTY_NAME, RegistryConstants.RESOURCES_RESULT_TYPE); registry.put(CUSTOM_QUERY_GET_ALL_BY_PROP, query); } params = new HashMap<String, String>(); params.put("1", propName); params.put("2", value); result = registry.executeQuery(CUSTOM_QUERY_GET_ALL_BY_PROP, params); paths = (String[]) result.getContent(); for (String prop : paths) { resource = registry.get(prop); retList.add(resourceToObject(resource)); } } catch (RegistryException e) { String message = "Error while retreving all objects from the registry path with property values"; log.error(message, e); throw IdentityException.error(message, e); } return retList; }
Example 18
Source File: PAPPolicyStoreReader.java From carbon-identity with Apache License 2.0 | 4 votes |
/** * Reads PolicyDTO for given registry resource * * @param resource Registry resource * @return PolicyDTO * @throws EntitlementException throws, if fails */ public PolicyDTO readPolicyDTO(Resource resource) throws EntitlementException { String policy = null; String policyId = null; AbstractPolicy absPolicy = null; PolicyDTO dto = null; try { policy = new String((byte[]) resource.getContent(), Charset.forName("UTF-8")); absPolicy = PAPPolicyReader.getInstance(null).getPolicy(policy); policyId = absPolicy.getId().toASCIIString(); dto = new PolicyDTO(); dto.setPolicyId(policyId); dto.setPolicy(policy); dto.setActive(Boolean.parseBoolean(resource.getProperty(PDPConstants.ACTIVE_POLICY))); String policyOrder = resource.getProperty(PDPConstants.POLICY_ORDER); if (policyOrder != null) { dto.setPolicyOrder(Integer.parseInt(policyOrder)); } else { dto.setPolicyOrder(0); } String version = resource.getProperty(PDPConstants.POLICY_VERSION); if (version != null) { dto.setVersion(version); } String lastModifiedTime = resource.getProperty(PDPConstants.LAST_MODIFIED_TIME); if (lastModifiedTime != null) { dto.setLastModifiedTime(lastModifiedTime); } String lastModifiedUser = resource.getProperty(PDPConstants.LAST_MODIFIED_USER); if (lastModifiedUser != null) { dto.setLastModifiedUser(lastModifiedUser); } dto.setPolicyType(resource.getProperty(PDPConstants.POLICY_TYPE)); String policyReferences = resource.getProperty(PDPConstants.POLICY_REFERENCE); if (policyReferences != null && policyReferences.trim().length() > 0) { dto.setPolicyIdReferences(policyReferences.split(PDPConstants.ATTRIBUTE_SEPARATOR)); } String policySetReferences = resource.getProperty(PDPConstants.POLICY_SET_REFERENCE); if (policySetReferences != null && policySetReferences.trim().length() > 0) { dto.setPolicySetIdReferences(policySetReferences.split(PDPConstants.ATTRIBUTE_SEPARATOR)); } //read policy meta data that is used for basic policy editor dto.setPolicyEditor(resource.getProperty(PDPConstants.POLICY_EDITOR_TYPE)); String basicPolicyEditorMetaDataAmount = resource.getProperty(PDPConstants. BASIC_POLICY_EDITOR_META_DATA_AMOUNT); if (basicPolicyEditorMetaDataAmount != null) { int amount = Integer.parseInt(basicPolicyEditorMetaDataAmount); String[] basicPolicyEditorMetaData = new String[amount]; for (int i = 0; i < amount; i++) { basicPolicyEditorMetaData[i] = resource. getProperty(PDPConstants.BASIC_POLICY_EDITOR_META_DATA + i); } dto.setPolicyEditorData(basicPolicyEditorMetaData); } PolicyAttributeBuilder policyAttributeBuilder = new PolicyAttributeBuilder(); dto.setAttributeDTOs(policyAttributeBuilder. getPolicyMetaDataFromRegistryProperties(resource.getProperties())); return dto; } catch (RegistryException e) { log.error("Error while loading entitlement policy " + policyId + " from PAP policy store", e); throw new EntitlementException("Error while loading entitlement policy " + policyId + " from PAP policy store"); } }
Example 19
Source File: AbstractDAO.java From carbon-identity-framework with Apache License 2.0 | 4 votes |
/** * Returns all the objects in a given registry path with a given property values. * * @param path registry path * @param propName name of the property to be matched * @param value value of the property to be matched * @return list of all objects matching the given property value in the given registry path * @throws IdentityException if an error occurs while reading the registry */ public List<T> getAllObjectsWithPropertyValue(String path, String propName, String value) throws IdentityException { Resource query = null; List<T> retList = null; Map<String, String> params = null; Resource result = null; String[] paths = null; Resource resource = null; if (log.isErrorEnabled()) { log.debug("Retrieving all objects from the registry path with property values " + path); } try { retList = new ArrayList<T>(); if (registry.resourceExists(CUSTOM_QUERY_GET_ALL_BY_PROP)) { //query = registry.get(CUSTOM_QUERY_GET_ALL_BY_PROP); } else { query = registry.newResource(); query.setContent(SQL_GET_ALL_BY_PROP); query.setMediaType(RegistryConstants.SQL_QUERY_MEDIA_TYPE); query.addProperty(RegistryConstants.RESULT_TYPE_PROPERTY_NAME, RegistryConstants.RESOURCES_RESULT_TYPE); registry.put(CUSTOM_QUERY_GET_ALL_BY_PROP, query); } params = new HashMap<String, String>(); params.put("1", propName); params.put("2", value); result = registry.executeQuery(CUSTOM_QUERY_GET_ALL_BY_PROP, params); paths = (String[]) result.getContent(); for (String prop : paths) { resource = registry.get(prop); retList.add(resourceToObject(resource)); } } catch (RegistryException e) { String message = "Error while retrieving all objects from the registry path with property values"; log.error(message, e); throw IdentityException.error(message, e); } return retList; }
Example 20
Source File: PAPPolicyStoreReader.java From carbon-identity-framework with Apache License 2.0 | 4 votes |
/** * Reads PolicyDTO for given registry resource * * @param resource Registry resource * @return PolicyDTO * @throws EntitlementException throws, if fails */ public PolicyDTO readPolicyDTO(Resource resource) throws EntitlementException { String policy = null; String policyId = null; AbstractPolicy absPolicy = null; PolicyDTO dto = null; try { policy = new String((byte[]) resource.getContent(), Charset.forName("UTF-8")); absPolicy = PAPPolicyReader.getInstance(null).getPolicy(policy); policyId = absPolicy.getId().toASCIIString(); dto = new PolicyDTO(); dto.setPolicyId(policyId); dto.setPolicy(policy); dto.setActive(Boolean.parseBoolean(resource.getProperty(PDPConstants.ACTIVE_POLICY))); String policyOrder = resource.getProperty(PDPConstants.POLICY_ORDER); if (policyOrder != null) { dto.setPolicyOrder(Integer.parseInt(policyOrder)); } else { dto.setPolicyOrder(0); } String version = resource.getProperty(PDPConstants.POLICY_VERSION); if (version != null) { dto.setVersion(version); } String lastModifiedTime = resource.getProperty(PDPConstants.LAST_MODIFIED_TIME); if (lastModifiedTime != null) { dto.setLastModifiedTime(lastModifiedTime); } String lastModifiedUser = resource.getProperty(PDPConstants.LAST_MODIFIED_USER); if (lastModifiedUser != null) { dto.setLastModifiedUser(lastModifiedUser); } dto.setPolicyType(resource.getProperty(PDPConstants.POLICY_TYPE)); String policyReferences = resource.getProperty(PDPConstants.POLICY_REFERENCE); if (policyReferences != null && policyReferences.trim().length() > 0) { dto.setPolicyIdReferences(policyReferences.split(PDPConstants.ATTRIBUTE_SEPARATOR)); } String policySetReferences = resource.getProperty(PDPConstants.POLICY_SET_REFERENCE); if (policySetReferences != null && policySetReferences.trim().length() > 0) { dto.setPolicySetIdReferences(policySetReferences.split(PDPConstants.ATTRIBUTE_SEPARATOR)); } //read policy meta data that is used for basic policy editor dto.setPolicyEditor(resource.getProperty(PDPConstants.POLICY_EDITOR_TYPE)); String basicPolicyEditorMetaDataAmount = resource.getProperty(PDPConstants. BASIC_POLICY_EDITOR_META_DATA_AMOUNT); if (basicPolicyEditorMetaDataAmount != null) { int amount = Integer.parseInt(basicPolicyEditorMetaDataAmount); String[] basicPolicyEditorMetaData = new String[amount]; for (int i = 0; i < amount; i++) { basicPolicyEditorMetaData[i] = resource. getProperty(PDPConstants.BASIC_POLICY_EDITOR_META_DATA + i); } dto.setPolicyEditorData(basicPolicyEditorMetaData); } PolicyAttributeBuilder policyAttributeBuilder = new PolicyAttributeBuilder(); dto.setAttributeDTOs(policyAttributeBuilder. getPolicyMetaDataFromRegistryProperties(resource.getProperties())); return dto; } catch (RegistryException e) { log.error("Error while loading entitlement policy " + policyId + " from PAP policy store", e); throw new EntitlementException("Error while loading entitlement policy " + policyId + " from PAP policy store"); } }