use of org.wso2.carbon.identity.application.common.model.xsd.Claim in project carbon-identity-framework by wso2.
the class ClaimDAO method getClaimId.
public int getClaimId(Connection connection, String claimDialectURI, String claimURI, int tenantId) throws ClaimMetadataException {
PreparedStatement prepStmt = null;
ResultSet rs = null;
int claimId = 0;
String query = SQLConstants.GET_CLAIM_ID;
try {
prepStmt = connection.prepareStatement(query);
prepStmt.setString(1, claimDialectURI);
prepStmt.setInt(2, tenantId);
prepStmt.setString(3, claimURI);
prepStmt.setInt(4, tenantId);
rs = prepStmt.executeQuery();
while (rs.next()) {
claimId = rs.getInt(SQLConstants.ID_COLUMN);
}
} catch (SQLException e) {
throw new ClaimMetadataException("Error while retrieving ID for claim " + claimURI + " in dialect " + claimDialectURI, e);
} finally {
IdentityDatabaseUtil.closeResultSet(rs);
IdentityDatabaseUtil.closeStatement(prepStmt);
}
if (claimId == 0) {
// TODO : Throw runtime exception?
throw new ClaimMetadataClientException(ERROR_CODE_MAPPED_TO_INVALID_LOCAL_CLAIM_URI.getCode(), String.format(ERROR_CODE_MAPPED_TO_INVALID_LOCAL_CLAIM_URI.getMessage(), claimURI, claimDialectURI));
}
return claimId;
}
use of org.wso2.carbon.identity.application.common.model.xsd.Claim in project carbon-identity-framework by wso2.
the class ClaimDAO method getClaimProperties.
public Map<String, String> getClaimProperties(Connection connection, int claimId, int tenantId) throws ClaimMetadataException {
Map<String, String> claimProperties = new HashMap<>();
String query = SQLConstants.GET_CLAIM_PROPERTIES;
try (PreparedStatement prepStmt = connection.prepareStatement(query)) {
prepStmt.setInt(1, claimId);
prepStmt.setInt(2, tenantId);
try (ResultSet rs = prepStmt.executeQuery()) {
while (rs.next()) {
String claimPropertyName = rs.getString(SQLConstants.PROPERTY_NAME_COLUMN);
String claimPropertyValue = rs.getString(SQLConstants.PROPERTY_VALUE_COLUMN);
claimProperties.put(claimPropertyName, claimPropertyValue);
}
}
} catch (SQLException e) {
throw new ClaimMetadataException("Error while retrieving claim properties", e);
}
return claimProperties;
}
use of org.wso2.carbon.identity.application.common.model.xsd.Claim in project carbon-identity-framework by wso2.
the class ClaimDAO method addClaimProperties.
public void addClaimProperties(Connection connection, int claimId, Map<String, String> claimProperties, int tenantId) throws ClaimMetadataException {
if (claimId > 0 && claimProperties != null) {
String query = SQLConstants.ADD_CLAIM_PROPERTY;
try (PreparedStatement prepStmt = connection.prepareStatement(query)) {
for (Map.Entry<String, String> property : claimProperties.entrySet()) {
prepStmt.setInt(1, claimId);
prepStmt.setString(2, property.getKey());
prepStmt.setString(3, property.getValue());
prepStmt.setInt(4, tenantId);
prepStmt.addBatch();
}
prepStmt.executeBatch();
} catch (SQLException e) {
throw new ClaimMetadataException("Error while adding claim properties", e);
}
}
}
use of org.wso2.carbon.identity.application.common.model.xsd.Claim in project carbon-identity-framework by wso2.
the class ClaimDAO method getClaims.
public Map<Integer, Claim> getClaims(Connection connection, String claimDialectURI, int tenantId) throws ClaimMetadataException {
Map<Integer, Claim> claimMap = new HashMap<>();
PreparedStatement prepStmt = null;
ResultSet rs = null;
String query = SQLConstants.GET_CLAIMS_BY_DIALECT;
try {
prepStmt = connection.prepareStatement(query);
prepStmt.setString(1, claimDialectURI);
prepStmt.setInt(2, tenantId);
prepStmt.setInt(3, tenantId);
// TODO : Get the logic reviewed : using executeQuery in a transaction.
rs = prepStmt.executeQuery();
while (rs.next()) {
String claimURI = rs.getString(SQLConstants.CLAIM_URI_COLUMN);
int claimId = rs.getInt(SQLConstants.ID_COLUMN);
claimMap.put(claimId, new Claim(claimDialectURI, claimURI));
}
} catch (SQLException e) {
throw new ClaimMetadataException("Error while listing claims for dialect " + claimDialectURI, e);
} finally {
IdentityDatabaseUtil.closeResultSet(rs);
IdentityDatabaseUtil.closeStatement(prepStmt);
}
return claimMap;
}
use of org.wso2.carbon.identity.application.common.model.xsd.Claim in project carbon-identity-framework by wso2.
the class ClaimDialectDAO method renameClaimDialect.
public void renameClaimDialect(ClaimDialect oldClaimDialect, ClaimDialect newClaimDialect, int tenantId) throws ClaimMetadataException {
Connection connection = IdentityDatabaseUtil.getDBConnection();
PreparedStatement prepStmt = null;
String query = SQLConstants.UPDATE_CLAIM_DIALECT;
try {
prepStmt = connection.prepareStatement(query);
prepStmt.setString(1, newClaimDialect.getClaimDialectURI());
prepStmt.setString(2, oldClaimDialect.getClaimDialectURI());
prepStmt.setInt(3, tenantId);
prepStmt.executeUpdate();
IdentityDatabaseUtil.commitTransaction(connection);
} catch (SQLException e) {
IdentityDatabaseUtil.rollbackTransaction(connection);
throw new ClaimMetadataException("Error while renaming claim dialect " + oldClaimDialect.getClaimDialectURI(), e);
} finally {
IdentityDatabaseUtil.closeStatement(prepStmt);
IdentityDatabaseUtil.closeConnection(connection);
}
}
Aggregations