Merge pull request #944 from sinthuja/master

Fixing https://github.com/wso2/product-iots/issues/1376
merge-requests/1/head
Harshan Liyanage 7 years ago committed by GitHub
commit 58cad70184

@ -33,6 +33,7 @@ import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
import org.wso2.carbon.device.mgt.common.group.mgt.GroupAlreadyExistException;
import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
import org.wso2.carbon.device.mgt.common.group.mgt.RoleDoesNotExistException;
import org.wso2.carbon.device.mgt.common.group.mgt.GroupNotExistException;
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceGroupList;
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList;
@ -144,7 +145,7 @@ public class GroupManagementServiceImpl implements GroupManagementService {
String msg = "Error occurred while adding new group.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (GroupAlreadyExistException e) {
} catch (GroupNotExistException e) {
String msg = "There is another group already exists with name '" + deviceGroup.getName() + "'.";
log.warn(msg);
return Response.status(Response.Status.CONFLICT).entity(msg).build();
@ -306,4 +307,4 @@ public class GroupManagementServiceImpl implements GroupManagementService {
}
}
}
}

@ -21,11 +21,8 @@ package org.wso2.carbon.device.mgt.jaxrs.service.impl.admin;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.GroupPaginationRequest;
import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.PaginationResult;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceGroupList;
import org.wso2.carbon.device.mgt.jaxrs.service.api.admin.GroupManagementAdminService;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
@ -33,7 +30,6 @@ import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
import javax.ws.rs.core.Response;
import java.util.ArrayList;
import java.util.List;
public class GroupManagementAdminServiceImpl implements GroupManagementAdminService {

@ -0,0 +1,55 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* WSO2 Inc. 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 org.wso2.carbon.device.mgt.common.group.mgt;
public class GroupNotExistException extends Exception{
private String errorMessage;
public GroupNotExistException(String msg, Exception nestedEx) {
super(msg, nestedEx);
setErrorMessage(msg);
}
public GroupNotExistException(String message, Throwable cause) {
super(message, cause);
setErrorMessage(message);
}
public GroupNotExistException(String msg) {
super(msg);
setErrorMessage(msg);
}
public GroupNotExistException() {
super();
}
public GroupNotExistException(Throwable cause) {
super(cause);
}
public String getErrorMessage() {
return errorMessage;
}
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
}

@ -27,6 +27,7 @@ import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
import org.wso2.carbon.device.mgt.common.group.mgt.GroupAlreadyExistException;
import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
import org.wso2.carbon.device.mgt.common.group.mgt.RoleDoesNotExistException;
import org.wso2.carbon.device.mgt.common.group.mgt.GroupNotExistException;
import java.util.List;
@ -53,7 +54,7 @@ public interface GroupManagementProviderService {
* @param groupId of the group.
* @throws GroupManagementException
*/
void updateGroup(DeviceGroup deviceGroup, int groupId) throws GroupManagementException, GroupAlreadyExistException;
void updateGroup(DeviceGroup deviceGroup, int groupId) throws GroupManagementException, GroupNotExistException;
/**
* Delete existing device group.

@ -73,9 +73,6 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
if (log.isDebugEnabled()) {
log.debug("Creating group '" + deviceGroup.getName() + "'");
}
if (deviceGroup == null) {
throw new GroupManagementException("DeviceGroup cannot be null.", new NullPointerException());
}
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
GroupManagementDAOFactory.beginTransaction();
@ -95,6 +92,8 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
String msg = "Error occurred while initiating transaction.";
log.error(msg, e);
throw new GroupManagementException(msg, e);
} catch (GroupAlreadyExistException ex) {
throw ex;
} catch (Exception e) {
String msg = "Error occurred in creating group '" + deviceGroup.getName() + "'";
log.error(msg, e);
@ -113,7 +112,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
*/
@Override
public void updateGroup(DeviceGroup deviceGroup, int groupId)
throws GroupManagementException, GroupAlreadyExistException {
throws GroupManagementException, GroupNotExistException {
if (deviceGroup == null) {
String msg = "Received incomplete data for updateGroup";
log.error(msg);
@ -122,30 +121,29 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
if (log.isDebugEnabled()) {
log.debug("update group '" + deviceGroup.getName() + "'");
}
if (deviceGroup == null) {
throw new GroupManagementException("DeviceGroup cannot be null.", new NullPointerException());
}
try {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
GroupManagementDAOFactory.beginTransaction();
DeviceGroup existingGroup = this.groupDAO.getGroup(deviceGroup.getName(), tenantId);
if (existingGroup == null || existingGroup.getGroupId() == groupId) {
DeviceGroup existingGroup = this.groupDAO.getGroup(groupId, tenantId);
if (existingGroup != null) {
this.groupDAO.updateGroup(deviceGroup, groupId, tenantId);
GroupManagementDAOFactory.commitTransaction();
} else {
throw new GroupAlreadyExistException("Group exist with name " + deviceGroup.getName());
throw new GroupNotExistException("Group with ID - '" + groupId + "' doesn't exists!");
}
} catch (GroupManagementDAOException e) {
GroupManagementDAOFactory.rollbackTransaction();
String msg = "Error occurred while modifying deviceGroup '" + deviceGroup.getName() + "'.";
String msg = "Error occurred while modifying device group with ID - '" + groupId + "'.";
log.error(msg, e);
throw new GroupManagementException(msg, e);
} catch (TransactionManagementException e) {
String msg = "Error occurred while initiating transaction.";
log.error(msg, e);
throw new GroupManagementException(msg, e);
} catch (GroupNotExistException ex) {
throw ex;
} catch (Exception e) {
String msg = "Error occurred in updating group '" + deviceGroup.getName() + "'";
String msg = "Error occurred in updating the device group with ID - '" + groupId + "'.";
log.error(msg, e);
throw new GroupManagementException(msg, e);
} finally {

@ -71,12 +71,14 @@ public class EmailSenderServiceImpl implements EmailSenderService {
if(EmailSenderDataHolder.getInstance().getConfigurationContextService()
.getServerConfigContext().getAxisConfiguration().getTransportOut(transportSenderName) == null){
log.warn("Email invitation is not sent as the email is not configured.");
} else {
threadPoolExecutor.submit(new EmailSender(recipient, emailData.getSubject(), emailData.getBody()));
}
} catch (ContentProcessingInterruptedException e) {
throw new EmailSendingFailedException("Error occurred while retrieving email content to be " +
"sent for recipient '" + recipient + "'", e);
}
threadPoolExecutor.submit(new EmailSender(recipient, emailData.getSubject(), emailData.getBody()));
}
}

Loading…
Cancel
Save