Skip to content

Commit

Permalink
Merge pull request #245 from mpmadhavig/add-is-db-mysql-check-for-sha…
Browse files Browse the repository at this point in the history
…reWithAllChildren-field
  • Loading branch information
mpmadhavig authored Sep 20, 2023
2 parents f5d2c7d + 5cb6fa5 commit f1221a3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.wso2.carbon.identity.organization.management.application.model.MainApplicationDO;
import org.wso2.carbon.identity.organization.management.application.model.SharedApplicationDO;
import org.wso2.carbon.identity.organization.management.service.exception.OrganizationManagementException;
import org.wso2.carbon.identity.organization.management.service.exception.OrganizationManagementServerException;

import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -57,6 +58,7 @@
import static org.wso2.carbon.identity.organization.management.service.constant.OrganizationManagementConstants.ErrorMessages.ERROR_CODE_ERROR_RESOLVING_SHARED_APPLICATION;
import static org.wso2.carbon.identity.organization.management.service.constant.OrganizationManagementConstants.ErrorMessages.ERROR_CODE_ERROR_UPDATING_APPLICATION_ATTRIBUTE;
import static org.wso2.carbon.identity.organization.management.service.util.Utils.handleServerException;
import static org.wso2.carbon.identity.organization.management.service.util.Utils.isMySqlDB;

/**
* This class implements the {@link OrgApplicationMgtDAO} interface.
Expand All @@ -69,14 +71,15 @@ public void addSharedApplication(String mainAppId, String ownerOrgId, String sha

NamedJdbcTemplate namedJdbcTemplate = getNewTemplate();
try {
String shareWithAllChildrenValue = getShareWithAllChildrenValue(shareWithAllChildren);
namedJdbcTemplate.withTransaction(template -> {
template.executeInsert(INSERT_SHARED_APP, namedPreparedStatement -> {
namedPreparedStatement.setString(DB_SCHEMA_COLUMN_NAME_MAIN_APP_ID, mainAppId);
namedPreparedStatement.setString(DB_SCHEMA_COLUMN_NAME_OWNER_ORG_ID, ownerOrgId);
namedPreparedStatement.setString(DB_SCHEMA_COLUMN_NAME_SHARED_APP_ID, sharedAppId);
namedPreparedStatement.setString(DB_SCHEMA_COLUMN_NAME_SHARED_ORG_ID, sharedOrgId);
namedPreparedStatement.setString(DB_SCHEMA_COLUMN_NAME_SHARE_WITH_ALL_CHILDREN,
String.valueOf(shareWithAllChildren));
shareWithAllChildrenValue);
}, null, false);
return null;
});
Expand Down Expand Up @@ -209,17 +212,34 @@ public void updateShareWithAllChildren(String mainApplicationId, String ownerOrg
boolean shareWithAllChildren) throws OrganizationManagementException {
NamedJdbcTemplate namedJdbcTemplate = getNewTemplate();
try {
String shareWithAllChildrenValue = getShareWithAllChildrenValue(shareWithAllChildren);
namedJdbcTemplate.withTransaction(template -> {
template.executeInsert(UPDATE_SHARE_WITH_ALL_CHILDREN, namedPreparedStatement -> {
namedPreparedStatement.setString(DB_SCHEMA_COLUMN_NAME_MAIN_APP_ID, mainApplicationId);
namedPreparedStatement.setString(DB_SCHEMA_COLUMN_NAME_OWNER_ORG_ID, ownerOrganizationId);
namedPreparedStatement.setString(DB_SCHEMA_COLUMN_NAME_SHARE_WITH_ALL_CHILDREN,
String.valueOf(shareWithAllChildren));
shareWithAllChildrenValue);
}, null, false);
return null;
});
} catch (TransactionException e) {
throw handleServerException(ERROR_CODE_ERROR_UPDATING_APPLICATION_ATTRIBUTE, e, mainApplicationId);
}
}

/**
* Get the value for the shareWithAllChildren column according to the db type.
*
* @param shareWithAllChildren The value of the shareWithAllChildren column.
* @return The value of the shareWithAllChildren column according to the db type.
* @throws OrganizationManagementServerException If an error occurs while getting the value.
*/
private String getShareWithAllChildrenValue(boolean shareWithAllChildren)
throws OrganizationManagementServerException {

if (isMySqlDB()) {
return shareWithAllChildren ? "1" : "0";
}
return String.valueOf(shareWithAllChildren);
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@
<org.wso2.identity.organization.mgt.imp.pkg.version.range>[1.0.0,2.0.0)
</org.wso2.identity.organization.mgt.imp.pkg.version.range>

<identity.organization.management.core.version>1.0.60</identity.organization.management.core.version>
<identity.organization.management.core.version>1.0.62</identity.organization.management.core.version>
<org.wso2.identity.organization.mgt.core.imp.pkg.version.range>[1.0.0,2.0.0)
</org.wso2.identity.organization.mgt.core.imp.pkg.version.range>

Expand Down

0 comments on commit f1221a3

Please sign in to comment.