mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Resolve comments
This commit is contained in:
parent
cd42a2c48f
commit
2e799a545f
@ -1,3 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package io.entgra.device.mgt.core.application.mgt.core.dao;
|
||||
|
||||
import io.entgra.device.mgt.core.application.mgt.common.dto.VppUserDTO;
|
||||
@ -6,9 +24,9 @@ import io.entgra.device.mgt.core.application.mgt.core.exception.ApplicationManag
|
||||
|
||||
public interface VppApplicationDAO {
|
||||
|
||||
int addVppUser(VppUserDTO userDTO) throws ApplicationManagementDAOException;
|
||||
int addVppUser(VppUserDTO userDTO, int tenantId) throws ApplicationManagementDAOException;
|
||||
|
||||
VppUserDTO updateVppUser(VppUserDTO userDTO) throws ApplicationManagementDAOException;
|
||||
VppUserDTO updateVppUser(VppUserDTO userDTO, int tenantId) throws ApplicationManagementDAOException;
|
||||
|
||||
VppUserDTO getUserByDMUsername(String emmUsername) throws ApplicationManagementDAOException;
|
||||
VppUserDTO getUserByDMUsername(String emmUsername, int tenantId) throws ApplicationManagementDAOException;
|
||||
}
|
||||
|
||||
@ -1,3 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package io.entgra.device.mgt.core.application.mgt.core.dao.impl.vpp;
|
||||
|
||||
import io.entgra.device.mgt.core.application.mgt.common.dto.VppUserDTO;
|
||||
@ -16,7 +34,7 @@ public class GenericVppApplicationDAOImpl extends AbstractDAOImpl implements Vp
|
||||
private static final Log log = LogFactory.getLog(GenericVppApplicationDAOImpl.class);
|
||||
|
||||
@Override
|
||||
public int addVppUser(VppUserDTO userDTO)
|
||||
public int addVppUser(VppUserDTO userDTO, int tenantId)
|
||||
throws ApplicationManagementDAOException {
|
||||
int vppUserId = -1;
|
||||
String sql = "INSERT INTO "
|
||||
@ -38,7 +56,7 @@ public class GenericVppApplicationDAOImpl extends AbstractDAOImpl implements Vp
|
||||
long currentTime = System.currentTimeMillis();
|
||||
stmt.setString(1, userDTO.getClientUserId());
|
||||
stmt.setString(2, userDTO.getDmUsername());
|
||||
stmt.setInt(3, userDTO.getTenantId());
|
||||
stmt.setInt(3, tenantId);
|
||||
stmt.setString(4, userDTO.getEmail());
|
||||
stmt.setString(5, userDTO.getInviteCode());
|
||||
stmt.setString(6, userDTO.getStatus());
|
||||
@ -65,7 +83,7 @@ public class GenericVppApplicationDAOImpl extends AbstractDAOImpl implements Vp
|
||||
}
|
||||
}
|
||||
|
||||
public VppUserDTO updateVppUser(VppUserDTO userDTO)
|
||||
public VppUserDTO updateVppUser(VppUserDTO userDTO, int tenantId)
|
||||
throws ApplicationManagementDAOException {
|
||||
|
||||
String sql = "UPDATE "
|
||||
@ -87,7 +105,7 @@ public class GenericVppApplicationDAOImpl extends AbstractDAOImpl implements Vp
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
stmt.setString(1, userDTO.getClientUserId());
|
||||
stmt.setString(2, userDTO.getDmUsername());
|
||||
stmt.setInt(3, userDTO.getTenantId());
|
||||
stmt.setInt(3, tenantId);
|
||||
stmt.setString(4, userDTO.getEmail());
|
||||
stmt.setString(5, userDTO.getInviteCode());
|
||||
stmt.setString(6, userDTO.getStatus());
|
||||
@ -112,7 +130,7 @@ public class GenericVppApplicationDAOImpl extends AbstractDAOImpl implements Vp
|
||||
}
|
||||
}
|
||||
|
||||
public VppUserDTO getUserByDMUsername(String emmUsername)
|
||||
public VppUserDTO getUserByDMUsername(String emmUsername, int tenantId)
|
||||
throws ApplicationManagementDAOException {
|
||||
String sql = "SELECT "
|
||||
+ "ID, "
|
||||
@ -126,11 +144,12 @@ public class GenericVppApplicationDAOImpl extends AbstractDAOImpl implements Vp
|
||||
+ "MANAGED_ID, "
|
||||
+ "TEMP_PASSWORD "
|
||||
+ "FROM AP_VPP_USER "
|
||||
+ "WHERE DM_USERNAME = ?";
|
||||
+ "WHERE DM_USERNAME = ? AND TENANT_ID = ?";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
stmt.setString(1, emmUsername);
|
||||
stmt.setInt(2, tenantId);
|
||||
try (ResultSet rs = stmt.executeQuery()) {
|
||||
return DAOUtil.loadVppUser(rs);
|
||||
}
|
||||
|
||||
@ -1,3 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package io.entgra.device.mgt.core.application.mgt.core.dao.impl.vpp;
|
||||
|
||||
import io.entgra.device.mgt.core.application.mgt.common.dto.VppUserDTO;
|
||||
@ -13,7 +31,7 @@ public class OracleVppApplicationDAOImpl extends GenericVppApplicationDAOImpl {
|
||||
private static final Log log = LogFactory.getLog(GenericVppApplicationDAOImpl.class);
|
||||
|
||||
@Override
|
||||
public int addVppUser(VppUserDTO userDTO)
|
||||
public int addVppUser(VppUserDTO userDTO, int tenantId)
|
||||
throws ApplicationManagementDAOException {
|
||||
int vppUserId = -1;
|
||||
String sql = "INSERT INTO "
|
||||
@ -35,7 +53,7 @@ public class OracleVppApplicationDAOImpl extends GenericVppApplicationDAOImpl {
|
||||
long currentTime = System.currentTimeMillis();
|
||||
stmt.setString(1, userDTO.getClientUserId());
|
||||
stmt.setString(2, userDTO.getDmUsername());
|
||||
stmt.setInt(3, userDTO.getTenantId());
|
||||
stmt.setInt(3, tenantId);
|
||||
stmt.setString(4, userDTO.getEmail());
|
||||
stmt.setString(5, userDTO.getInviteCode());
|
||||
stmt.setString(6, userDTO.getStatus());
|
||||
|
||||
@ -1,3 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package io.entgra.device.mgt.core.application.mgt.core.dao.impl.vpp;
|
||||
|
||||
import io.entgra.device.mgt.core.application.mgt.common.dto.VppUserDTO;
|
||||
@ -12,7 +30,7 @@ public class PostgreSQLVppApplicationDAO extends GenericVppApplicationDAOImpl {
|
||||
|
||||
private static final Log log = LogFactory.getLog(GenericVppApplicationDAOImpl.class);
|
||||
|
||||
public int addVppUser(VppUserDTO userDTO)
|
||||
public int addVppUser(VppUserDTO userDTO, int tenantId)
|
||||
throws ApplicationManagementDAOException {
|
||||
int vppUserId = -1;
|
||||
String sql = "INSERT INTO "
|
||||
@ -34,7 +52,7 @@ public class PostgreSQLVppApplicationDAO extends GenericVppApplicationDAOImpl {
|
||||
long currentTime = System.currentTimeMillis();
|
||||
stmt.setString(1, userDTO.getClientUserId());
|
||||
stmt.setString(2, userDTO.getDmUsername());
|
||||
stmt.setInt(3, userDTO.getTenantId());
|
||||
stmt.setInt(3, tenantId);
|
||||
stmt.setString(4, userDTO.getEmail());
|
||||
stmt.setString(5, userDTO.getInviteCode());
|
||||
stmt.setString(6, userDTO.getStatus());
|
||||
|
||||
@ -1,3 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package io.entgra.device.mgt.core.application.mgt.core.dao.impl.vpp;
|
||||
|
||||
public class SQLServerVppApplicationDAOImpl extends GenericVppApplicationDAOImpl {
|
||||
|
||||
@ -45,6 +45,7 @@ import io.entgra.device.mgt.core.application.mgt.core.util.VppHttpUtil;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@ -77,6 +78,9 @@ public class VppApplicationManagerImpl implements VPPApplicationManager {
|
||||
|
||||
@Override
|
||||
public VppUserDTO addUser(VppUserDTO userDTO) throws ApplicationManagementException {
|
||||
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||
|
||||
// Call the API to add
|
||||
try {
|
||||
VppItuneUserDTO ituneUserDTO = userDTO;
|
||||
@ -105,7 +109,7 @@ public class VppApplicationManagerImpl implements VPPApplicationManager {
|
||||
log.error("userDTO " + userDTO.toString());
|
||||
try {
|
||||
ConnectionManagerUtil.beginDBTransaction();
|
||||
if (vppApplicationDAO.addVppUser(userDTO) != -1) {
|
||||
if (vppApplicationDAO.addVppUser(userDTO, tenantId) != -1) {
|
||||
ConnectionManagerUtil.commitDBTransaction();
|
||||
return userDTO;
|
||||
}
|
||||
@ -140,9 +144,10 @@ public class VppApplicationManagerImpl implements VPPApplicationManager {
|
||||
|
||||
@Override
|
||||
public VppUserDTO getUserByDMUsername(String emmUsername) throws ApplicationManagementException {
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||
try {
|
||||
ConnectionManagerUtil.openDBConnection();
|
||||
return vppApplicationDAO.getUserByDMUsername(emmUsername);
|
||||
return vppApplicationDAO.getUserByDMUsername(emmUsername, tenantId);
|
||||
} catch (DBConnectionException e) {
|
||||
String msg = "DB Connection error occurs while getting vpp User data related to EMM user " + emmUsername + ".";
|
||||
log.error(msg, e);
|
||||
@ -158,6 +163,7 @@ public class VppApplicationManagerImpl implements VPPApplicationManager {
|
||||
|
||||
@Override
|
||||
public void updateUser(VppUserDTO userDTO) throws ApplicationManagementException {
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||
VppItuneUserDTO ituneUserDTO = userDTO;
|
||||
VppItuneUserRequestWrapper wrapper = new VppItuneUserRequestWrapper();
|
||||
wrapper.getUser().add(ituneUserDTO);
|
||||
@ -173,7 +179,7 @@ public class VppApplicationManagerImpl implements VPPApplicationManager {
|
||||
|
||||
try {
|
||||
ConnectionManagerUtil.beginDBTransaction();
|
||||
if (vppApplicationDAO.updateVppUser(userDTO) == null) {
|
||||
if (vppApplicationDAO.updateVppUser(userDTO, tenantId) == null) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
String msg = "Unable to update the Vpp user " +userDTO.getId();
|
||||
log.error(msg);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user