use of org.wso2.carbon.identity.claim.metadata.mgt.model.AttributeMapping in project siddhi by wso2.
the class InputEventHandler method sendEvents.
public void sendEvents(Event[] events) throws InterruptedException {
try {
if (latencyTracker != null && siddhiAppContext.isStatsEnabled()) {
latencyTracker.markOut();
}
String[] transportProperties = trpProperties.get();
trpProperties.remove();
long currentTimestamp = timestampGenerator.currentTime();
for (Event event : events) {
if (event.getTimestamp() == -1) {
event.setTimestamp(currentTimestamp);
}
for (int i = 0; i < transportMapping.size(); i++) {
AttributeMapping attributeMapping = transportMapping.get(i);
event.getData()[attributeMapping.getPosition()] = transportProperties[i];
}
}
inputEventHandlerCallback.sendEvents(events);
} catch (RuntimeException e) {
LOG.error(ExceptionUtil.getMessageWithContext(e, siddhiAppContext) + " Error in applying transport property mapping for '" + sourceType + "' source at '" + inputHandler.getStreamId() + "' stream.", e);
} finally {
trpProperties.remove();
}
}
use of org.wso2.carbon.identity.claim.metadata.mgt.model.AttributeMapping in project carbon-identity-framework by wso2.
the class LocalClaimDAO method getClaimAttributeMappingsOfDialect.
private Map<Integer, List<AttributeMapping>> getClaimAttributeMappingsOfDialect(Connection connection, String claimDialectURI, int tenantId) throws ClaimMetadataException {
Map<Integer, List<AttributeMapping>> attributeMappings = new HashMap<>();
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
try {
preparedStatement = connection.prepareStatement(SQLConstants.GET_MAPPED_ATTRIBUTES);
preparedStatement.setString(1, claimDialectURI);
preparedStatement.setInt(2, tenantId);
preparedStatement.setInt(3, tenantId);
preparedStatement.setInt(4, tenantId);
resultSet = preparedStatement.executeQuery();
while (resultSet.next()) {
String userStoreDomainName = resultSet.getString(SQLConstants.USER_STORE_DOMAIN_NAME_COLUMN);
String attributeName = resultSet.getString(SQLConstants.ATTRIBUTE_NAME_COLUMN);
int localClaimId = resultSet.getInt(SQLConstants.LOCAL_CLAIM_ID_COLUMN);
AttributeMapping attributeMapping = new AttributeMapping(userStoreDomainName, attributeName);
List<AttributeMapping> existingAttributeMapping = attributeMappings.get(localClaimId);
if (existingAttributeMapping == null) {
existingAttributeMapping = new ArrayList<>();
}
existingAttributeMapping.add(attributeMapping);
attributeMappings.put(localClaimId, existingAttributeMapping);
}
} catch (SQLException e) {
throw new ClaimMetadataException("Error occurred while retrieving attribute mappings.", e);
} finally {
IdentityDatabaseUtil.closeResultSet(resultSet);
IdentityDatabaseUtil.closeStatement(preparedStatement);
}
return attributeMappings;
}
use of org.wso2.carbon.identity.claim.metadata.mgt.model.AttributeMapping in project carbon-identity-framework by wso2.
the class LocalClaimDAO method addClaimAttributeMappings.
private void addClaimAttributeMappings(Connection connection, int localClaimId, List<AttributeMapping> attributeMappings, int tenantId) throws ClaimMetadataException {
PreparedStatement prepStmt = null;
if (localClaimId > 0 && attributeMappings != null) {
try {
String query = SQLConstants.ADD_CLAIM_MAPPED_ATTRIBUTE;
prepStmt = connection.prepareStatement(query);
for (AttributeMapping attributeMapping : attributeMappings) {
if (StringUtils.isBlank(attributeMapping.getUserStoreDomain())) {
throw new ClaimMetadataException("User store domain of mapped Attribute cannot be empty for " + "the local claim id : " + localClaimId);
} else if (StringUtils.isBlank(attributeMapping.getAttributeName())) {
throw new ClaimMetadataException("Mapped attribute of the local claim id : " + localClaimId + " cannot be empty");
}
prepStmt.setInt(1, localClaimId);
prepStmt.setString(2, attributeMapping.getUserStoreDomain());
prepStmt.setString(3, attributeMapping.getAttributeName());
prepStmt.setInt(4, tenantId);
prepStmt.addBatch();
}
prepStmt.executeBatch();
} catch (SQLException e) {
throw new ClaimMetadataException("Error while adding attribute mappings", e);
} finally {
IdentityDatabaseUtil.closeStatement(prepStmt);
}
}
}
use of org.wso2.carbon.identity.claim.metadata.mgt.model.AttributeMapping in project carbon-identity-framework by wso2.
the class ClaimMetadataUtils method convertLocalClaimToLocalClaimDTO.
public static LocalClaimDTO convertLocalClaimToLocalClaimDTO(LocalClaim localClaim) {
LocalClaimDTO localClaimDTO = new LocalClaimDTO();
localClaimDTO.setLocalClaimURI(localClaim.getClaimURI());
// Convert List<AttributeMapping> to AttributeMappingDTO[]
List<AttributeMapping> attributeMappings = localClaim.getMappedAttributes();
AttributeMappingDTO[] attributeMappingDTOs = new AttributeMappingDTO[attributeMappings.size()];
int i = 0;
for (AttributeMapping attributeMapping : attributeMappings) {
AttributeMappingDTO attributeMappingDTO = new AttributeMappingDTO();
attributeMappingDTO.setUserStoreDomain(attributeMapping.getUserStoreDomain());
attributeMappingDTO.setAttributeName(attributeMapping.getAttributeName());
attributeMappingDTOs[i] = attributeMappingDTO;
i++;
}
localClaimDTO.setAttributeMappings(attributeMappingDTOs);
// Convert Map<String, String> to ClaimPropertyDTO[]
Map<String, String> claimProperties = localClaim.getClaimProperties();
ClaimPropertyDTO[] claimPropertyDTOs = new ClaimPropertyDTO[claimProperties.size()];
int j = 0;
for (Map.Entry<String, String> claimPropertyEntry : claimProperties.entrySet()) {
ClaimPropertyDTO claimProperty = new ClaimPropertyDTO();
claimProperty.setPropertyName(claimPropertyEntry.getKey());
claimProperty.setPropertyValue(claimPropertyEntry.getValue());
claimPropertyDTOs[j] = claimProperty;
j++;
}
localClaimDTO.setClaimProperties(claimPropertyDTOs);
return localClaimDTO;
}
use of org.wso2.carbon.identity.claim.metadata.mgt.model.AttributeMapping in project carbon-identity-framework by wso2.
the class ClaimMetadataUtils method convertLocalClaimDTOToLocalClaim.
public static LocalClaim convertLocalClaimDTOToLocalClaim(LocalClaimDTO localClaimDTO) {
// TODO : Validate if localClaimDTO null???
LocalClaim localClaim = new LocalClaim(localClaimDTO.getLocalClaimURI());
// Convert AttributeMappingDTO[] to List<AttributeMapping>
if (localClaimDTO.getAttributeMappings() != null) {
List<AttributeMapping> attributeMappings = new ArrayList<>();
for (AttributeMappingDTO attributeMappingDTO : localClaimDTO.getAttributeMappings()) {
attributeMappings.add(new AttributeMapping(attributeMappingDTO.getUserStoreDomain(), attributeMappingDTO.getAttributeName()));
}
localClaim.setMappedAttributes(attributeMappings);
}
// Convert ClaimPropertyDTO[] to Map<String, String>
if (localClaimDTO.getClaimProperties() != null) {
Map<String, String> claimProperties = new HashMap<>();
for (ClaimPropertyDTO claimPropertyDTO : localClaimDTO.getClaimProperties()) {
claimProperties.put(claimPropertyDTO.getPropertyName(), claimPropertyDTO.getPropertyValue());
}
localClaim.setClaimProperties(claimProperties);
}
return localClaim;
}
Aggregations