use of org.wso2.carbon.identity.entitlement.stub.dto.PublisherPropertyDTO in project carbon-identity-framework by wso2.
the class SimplePAPStatusDataHandler method readStatus.
private synchronized List<StatusHolder> readStatus(String path, String about) throws EntitlementException {
Resource resource = null;
Registry registry = null;
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
registry = EntitlementServiceComponent.getRegistryService().getGovernanceSystemRegistry(tenantId);
if (registry.resourceExists(path)) {
resource = registry.get(path);
}
} catch (RegistryException e) {
log.error(e);
throw new EntitlementException("Error while persisting policy status", e);
}
List<StatusHolder> statusHolders = new ArrayList<StatusHolder>();
if (resource != null && resource.getProperties() != null) {
Properties properties = resource.getProperties();
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
PublisherPropertyDTO dto = new PublisherPropertyDTO();
dto.setId((String) entry.getKey());
Object value = entry.getValue();
if (value instanceof ArrayList) {
List list = (ArrayList) entry.getValue();
if (list != null && list.size() > 0 && list.get(0) != null) {
StatusHolder statusHolder = new StatusHolder(about);
if (list.size() > 0 && list.get(0) != null) {
statusHolder.setType((String) list.get(0));
}
if (list.size() > 1 && list.get(1) != null) {
statusHolder.setTimeInstance((String) list.get(1));
} else {
continue;
}
if (list.size() > 2 && list.get(2) != null) {
String user = (String) list.get(2);
statusHolder.setUser(user);
} else {
continue;
}
if (list.size() > 3 && list.get(3) != null) {
statusHolder.setKey((String) list.get(3));
}
if (list.size() > 4 && list.get(4) != null) {
statusHolder.setSuccess(Boolean.parseBoolean((String) list.get(4)));
}
if (list.size() > 5 && list.get(5) != null) {
statusHolder.setMessage((String) list.get(5));
}
if (list.size() > 6 && list.get(6) != null) {
statusHolder.setTarget((String) list.get(6));
}
if (list.size() > 7 && list.get(7) != null) {
statusHolder.setTargetAction((String) list.get(7));
}
if (list.size() > 8 && list.get(8) != null) {
statusHolder.setVersion((String) list.get(8));
}
statusHolders.add(statusHolder);
}
}
}
}
if (statusHolders.size() > 0) {
StatusHolder[] array = statusHolders.toArray(new StatusHolder[statusHolders.size()]);
java.util.Arrays.sort(array, new StatusHolderComparator());
if (statusHolders.size() > maxRecodes) {
statusHolders = new ArrayList<StatusHolder>();
for (int i = 0; i < maxRecodes; i++) {
statusHolders.add(array[i]);
}
persistStatus(path, statusHolders, true);
} else {
statusHolders = new ArrayList<StatusHolder>(Arrays.asList(array));
}
}
return statusHolders;
}
use of org.wso2.carbon.identity.entitlement.stub.dto.PublisherPropertyDTO in project carbon-identity-framework by wso2.
the class PolicyPublisher method populateProperties.
private void populateProperties(PublisherDataHolder holder, PublisherDataHolder oldHolder, Resource resource) {
PublisherPropertyDTO[] propertyDTOs = holder.getPropertyDTOs();
for (PublisherPropertyDTO dto : propertyDTOs) {
if (dto.getId() != null && dto.getValue() != null && dto.getValue().trim().length() > 0) {
ArrayList<String> list = new ArrayList<String>();
if (dto.isSecret()) {
PublisherPropertyDTO propertyDTO = null;
if (oldHolder != null) {
propertyDTO = oldHolder.getPropertyDTO(dto.getId());
}
if (propertyDTO == null || !propertyDTO.getValue().equalsIgnoreCase(dto.getValue())) {
try {
String encryptedValue = CryptoUtil.getDefaultCryptoUtil().encryptAndBase64Encode(dto.getValue().getBytes());
dto.setValue(encryptedValue);
} catch (CryptoException e) {
log.error("Error while encrypting secret value of subscriber. " + "Secret would not be persist.", e);
continue;
}
}
}
list.add(dto.getValue());
list.add(dto.getDisplayName());
list.add(Integer.toString(dto.getDisplayOrder()));
list.add(Boolean.toString(dto.isRequired()));
list.add(Boolean.toString(dto.isSecret()));
resource.setProperty(dto.getId(), list);
}
}
resource.setProperty(PublisherDataHolder.MODULE_NAME, holder.getModuleName());
}
use of org.wso2.carbon.identity.entitlement.stub.dto.PublisherPropertyDTO in project product-is by wso2.
the class EntitlementPolicyAdminServiceTestCase method testUpdateSubscriber.
// @Test(groups = "wso2.is", description = "Check getting subscriber Ids", dependsOnMethods="testOrderPolicy")
// public void testEnableDisablePolicy() throws Exception{
// entitlementPolicyClient.enableDisablePolicy(POLICY_1_ID, false);
// entitlementPolicyClient.enableDisablePolicy(POLICY_1_ID, true);
// }
@Test(groups = "wso2.is", description = "Check getting subscriber", dependsOnMethods = "testOrderPolicy")
public void testUpdateSubscriber() throws Exception {
PublisherDataHolder holder = new PublisherDataHolder();
holder.setModuleName("test2");
PublisherPropertyDTO propertyDto = new PublisherPropertyDTO();
propertyDto.setId("subscriberId");
propertyDto.setValue("1002");
PublisherPropertyDTO[] propertyDTOs = new PublisherPropertyDTO[1];
propertyDTOs[0] = propertyDto;
holder.setPropertyDTOs(propertyDTOs);
entitlementPolicyClient.updateSubscriber(holder);
}
use of org.wso2.carbon.identity.entitlement.stub.dto.PublisherPropertyDTO in project product-is by wso2.
the class EntitlementPolicyAdminServiceTestCase method testAddSubscriber.
@Test(groups = "wso2.is", description = "Check getting subscriber", dependsOnMethods = "testGetStatusData")
public void testAddSubscriber() throws Exception {
PublisherDataHolder holder = new PublisherDataHolder();
holder.setModuleName("test");
PublisherPropertyDTO propertyDto = new PublisherPropertyDTO();
propertyDto.setId("subscriberId");
propertyDto.setValue("1001");
PublisherPropertyDTO[] propertyDTOs = new PublisherPropertyDTO[1];
propertyDTOs[0] = propertyDto;
holder.setPropertyDTOs(propertyDTOs);
entitlementPolicyClient.addSubscriber(holder);
}
use of org.wso2.carbon.identity.entitlement.stub.dto.PublisherPropertyDTO in project carbon-identity-framework by wso2.
the class PropertyDTOComparator method compare.
@Override
public int compare(Object o1, Object o2) {
PublisherPropertyDTO dto1 = (PublisherPropertyDTO) o1;
PublisherPropertyDTO dto2 = (PublisherPropertyDTO) o2;
if (dto1.getDisplayOrder() < dto2.getDisplayOrder()) {
return -1;
} else if (dto1.getDisplayOrder() == dto2.getDisplayOrder()) {
return 0;
} else {
return 1;
}
}
Aggregations