Skip to content

Commit

Permalink
refactored editEventClassFamily to use ECF version as argument only
Browse files Browse the repository at this point in the history
  • Loading branch information
nocs00 committed Jul 11, 2016
1 parent 5423fab commit 873a0f0
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 52 deletions.
Expand Up @@ -55,10 +55,10 @@ public interface EventClassService {
/**
* Save event class family.
*
* @param eventClassFamilyDto the event class family dto
* @param eventClassFamilyVersionDto the event class family version dto
* @return the event class family dto
*/
EventClassFamilyDto saveEventClassFamily(EventClassFamilyDto eventClassFamilyDto);
EventClassFamilyDto saveEventClassFamily(EventClassFamilyVersionDto eventClassFamilyVersionDto);

/**
* Add event class family schema.
Expand Down
Expand Up @@ -27,8 +27,6 @@
import java.util.Comparator;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.kaaproject.avro.ui.shared.NamesValidator;
import org.kaaproject.kaa.common.dto.event.EventClassDto;
import org.kaaproject.kaa.common.dto.event.EventClassFamilyDto;
import org.kaaproject.kaa.common.dto.event.EventClassFamilyVersionDto;
Expand Down Expand Up @@ -102,37 +100,17 @@ public List<EventClassFamilyVersionDto> findEventClassFamilyVersionsById(String

@Override
public EventClassFamilyDto saveEventClassFamily(
EventClassFamilyDto eventClassFamilyDto) {
EventClassFamilyVersionDto eventClassFamilyVersionDto) {
EventClassFamilyDto savedEventClassFamilyDto = null;
if (isValidSqlObject(eventClassFamilyDto)) {
if (eventClassFamilyDao.validateName(eventClassFamilyDto.getTenantId(), eventClassFamilyDto.getId(), eventClassFamilyDto.getName())) {
if (StringUtils.isBlank(eventClassFamilyDto.getId())) {
if (NamesValidator.validateNamespace(eventClassFamilyDto.getNamespace())) {
if (NamesValidator.validateClassName(eventClassFamilyDto.getClassName())) {
if (eventClassFamilyDao.validateClassName(eventClassFamilyDto.getTenantId(), eventClassFamilyDto.getId(), eventClassFamilyDto.getClassName())) {
eventClassFamilyDto.setCreatedTime(System.currentTimeMillis());
} else {
LOG.debug("Can't save event class family. Class name should be unique within the tenant.");
throw new IncorrectParameterException("Incorrect event class family. Class name should be unique within the tenant.");
}
} else {
LOG.debug("Can't save event class family. Class name [{}] is not valid.", eventClassFamilyDto.getClassName());
throw new IncorrectParameterException("Incorrect event class family. Class name is not valid. '" + eventClassFamilyDto.getClassName() + "' is not a valid identifier.");
}
} else {
LOG.debug("Can't save event class family. Namespace [{}] is not valid.", eventClassFamilyDto.getNamespace());
throw new IncorrectParameterException("Incorrect event class family. Namespace is not valid. '" + eventClassFamilyDto.getNamespace() + "' is not a valid identifier.");
}
}
EventClassFamily ecf = new EventClassFamily(eventClassFamilyDto);
List<EventClassFamilyVersion> schemas = new ArrayList<>();
findEventClassFamilyVersionsById(eventClassFamilyDto.getId()).forEach(s -> schemas.add(new EventClassFamilyVersion(s)));
ecf.setSchemas(schemas);
savedEventClassFamilyDto = getDto(eventClassFamilyDao.save(ecf));
} else {
LOG.debug("Can't save event class family. Name should be unique within the tenant.");
throw new IncorrectParameterException("Incorrect event class family. Name should be unique within the tenant.");
}
if (isValidSqlObject(eventClassFamilyVersionDto)) {
savedEventClassFamilyDto = getDto(eventClassFamilyDao.findById(eventClassFamilyVersionDto.getId()));
savedEventClassFamilyDto.setCreatedTime(System.currentTimeMillis());
EventClassFamily ecf = new EventClassFamily(savedEventClassFamilyDto);
List<EventClassFamilyVersion> schemas = new ArrayList<>();
findEventClassFamilyVersionsById(eventClassFamilyVersionDto.getId()).forEach(s -> schemas.add(new EventClassFamilyVersion(s)));
schemas.add(new EventClassFamilyVersion(eventClassFamilyVersionDto));
ecf.setSchemas(schemas);
savedEventClassFamilyDto = getDto(eventClassFamilyDao.save(ecf));
}
return savedEventClassFamilyDto;
}
Expand Down
Expand Up @@ -66,6 +66,7 @@
import org.kaaproject.kaa.common.dto.event.EcfInfoDto;
import org.kaaproject.kaa.common.dto.event.EventClassDto;
import org.kaaproject.kaa.common.dto.event.EventClassFamilyDto;
import org.kaaproject.kaa.common.dto.event.EventClassFamilyVersionDto;
import org.kaaproject.kaa.common.dto.event.EventClassType;
import org.kaaproject.kaa.common.dto.file.FileData;
import org.kaaproject.kaa.common.dto.logs.LogAppenderDto;
Expand All @@ -76,7 +77,6 @@
import org.kaaproject.kaa.server.admin.services.entity.CreateUserResult;
import org.kaaproject.kaa.server.admin.services.util.Utils;
import org.kaaproject.kaa.server.admin.servlet.ServletUtils;
import org.kaaproject.kaa.server.admin.shared.schema.NotificationSchemaViewDto;
import org.kaaproject.kaa.server.admin.shared.services.KaaAdminService;
import org.kaaproject.kaa.server.admin.shared.services.KaaAdminServiceException;
import org.kaaproject.kaa.server.admin.shared.services.KaaAuthService;
Expand Down Expand Up @@ -1930,16 +1930,16 @@ public EventClassFamilyDto getEventClassFamily(@PathVariable String eventClassFa
/**
* Edits event class family to the list of all event class families.
*
* @param eventClassFamily
* the event class family
* @param eventClassFamilyVersion
* the version of event class family
* @return the event class family dto
* @throws KaaAdminServiceException
* the kaa admin service exception
*/
@RequestMapping(value = "eventClassFamily", method = RequestMethod.POST)
@ResponseBody
public EventClassFamilyDto editEventClassFamily(@RequestBody EventClassFamilyDto eventClassFamily) throws KaaAdminServiceException {
return kaaAdminService.editEventClassFamily(eventClassFamily);
public EventClassFamilyDto editEventClassFamily(@RequestBody EventClassFamilyVersionDto eventClassFamilyVersion) throws KaaAdminServiceException {
return kaaAdminService.editEventClassFamily(eventClassFamilyVersion);
}

/**
Expand Down
Expand Up @@ -99,6 +99,7 @@
import org.kaaproject.kaa.common.dto.event.EcfInfoDto;
import org.kaaproject.kaa.common.dto.event.EventClassDto;
import org.kaaproject.kaa.common.dto.event.EventClassFamilyDto;
import org.kaaproject.kaa.common.dto.event.EventClassFamilyVersionDto;
import org.kaaproject.kaa.common.dto.event.EventClassType;
import org.kaaproject.kaa.common.dto.file.FileData;
import org.kaaproject.kaa.common.dto.logs.LogAppenderDto;
Expand Down Expand Up @@ -128,10 +129,8 @@
import org.kaaproject.kaa.server.admin.shared.services.KaaAdminService;
import org.kaaproject.kaa.server.admin.shared.services.KaaAdminServiceException;
import org.kaaproject.kaa.server.admin.shared.services.ServiceErrorCode;
import org.kaaproject.kaa.server.common.core.schema.BaseSchema;
import org.kaaproject.kaa.server.common.core.schema.KaaSchemaFactoryImpl;
import org.kaaproject.kaa.server.common.dao.exception.NotFoundException;
import org.kaaproject.kaa.server.common.dao.model.sql.CTLSchema;
import org.kaaproject.kaa.server.common.plugin.KaaPluginConfig;
import org.kaaproject.kaa.server.common.plugin.PluginConfig;
import org.kaaproject.kaa.server.common.plugin.PluginType;
Expand Down Expand Up @@ -2698,19 +2697,19 @@ public EventClassFamilyDto getEventClassFamily(String eventClassFamilyId) throws
}

@Override
public EventClassFamilyDto editEventClassFamily(EventClassFamilyDto eventClassFamily) throws KaaAdminServiceException {
public EventClassFamilyDto editEventClassFamily(EventClassFamilyVersionDto eventClassFamilyVersion) throws KaaAdminServiceException {
checkAuthority(KaaAuthorityDto.TENANT_ADMIN);
try {
if (!isEmpty(eventClassFamily.getId())) {
EventClassFamilyDto storedEventClassFamily = controlService.getEventClassFamily(eventClassFamily.getId());
EventClassFamilyDto storedEventClassFamily = null;
if (!isEmpty(eventClassFamilyVersion.getId())) {
storedEventClassFamily = controlService.getEventClassFamily(eventClassFamilyVersion.getId());
Utils.checkNotNull(storedEventClassFamily);
checkTenantId(storedEventClassFamily.getTenantId());
} else {
String username = getCurrentUser().getUsername();
eventClassFamily.setCreatedUsername(username);
eventClassFamilyVersion.setCreatedUsername(username);
}
eventClassFamily.setTenantId(getTenantId());
return controlService.editEventClassFamily(eventClassFamily);
return controlService.editEventClassFamily(eventClassFamilyVersion);
} catch (Exception e) {
throw Utils.handleException(e);
}
Expand Down
Expand Up @@ -55,6 +55,7 @@
import org.kaaproject.kaa.common.dto.event.EcfInfoDto;
import org.kaaproject.kaa.common.dto.event.EventClassDto;
import org.kaaproject.kaa.common.dto.event.EventClassFamilyDto;
import org.kaaproject.kaa.common.dto.event.EventClassFamilyVersionDto;
import org.kaaproject.kaa.common.dto.event.EventClassType;
import org.kaaproject.kaa.common.dto.file.FileData;
import org.kaaproject.kaa.common.dto.logs.LogAppenderDto;
Expand Down Expand Up @@ -309,7 +310,7 @@ public interface KaaAdminService extends RemoteService {

EventClassFamilyDto getEventClassFamily(String eventClassFamilyId) throws KaaAdminServiceException;

EventClassFamilyDto editEventClassFamily(EventClassFamilyDto eventClassFamily) throws KaaAdminServiceException;
EventClassFamilyDto editEventClassFamily(EventClassFamilyVersionDto eventClassFamilyVersion) throws KaaAdminServiceException;

void addEventClassFamilySchemaForm(String eventClassFamilyId, RecordField schemaForm) throws KaaAdminServiceException;

Expand Down
Expand Up @@ -59,6 +59,7 @@
import org.kaaproject.kaa.common.dto.event.EcfInfoDto;
import org.kaaproject.kaa.common.dto.event.EventClassDto;
import org.kaaproject.kaa.common.dto.event.EventClassFamilyDto;
import org.kaaproject.kaa.common.dto.event.EventClassFamilyVersionDto;
import org.kaaproject.kaa.common.dto.event.EventClassType;
import org.kaaproject.kaa.common.dto.file.FileData;
import org.kaaproject.kaa.common.dto.logs.LogAppenderDto;
Expand Down Expand Up @@ -1007,7 +1008,7 @@ List<NotificationSchemaDto> findNotificationSchemasByAppIdAndType(String applica
* @throws ControlServiceException
* the control service exception
*/
EventClassFamilyDto editEventClassFamily(EventClassFamilyDto eventClassFamily) throws ControlServiceException;
EventClassFamilyDto editEventClassFamily(EventClassFamilyVersionDto eventClassFamilyVersion) throws ControlServiceException;

/**
* Gets the event class families by tenant id.
Expand Down
Expand Up @@ -1482,11 +1482,11 @@ public List<VersionDto> getLogSchemaVersionsByApplicationId(String applicationId
*
* @see org.kaaproject.kaa.server.control.service.ControlService#
* editEventClassFamily
* (org.kaaproject.kaa.common.dto.event.EventClassFamilyDto)
* (org.kaaproject.kaa.common.dto.event.EventClassFamilyVersionDto)
*/
@Override
public EventClassFamilyDto editEventClassFamily(EventClassFamilyDto eventClassFamily) throws ControlServiceException {
return eventClassService.saveEventClassFamily(eventClassFamily);
public EventClassFamilyDto editEventClassFamily(EventClassFamilyVersionDto eventClassFamilyVersion) throws ControlServiceException {
return eventClassService.saveEventClassFamily(eventClassFamilyVersion);
}

/*
Expand Down

0 comments on commit 873a0f0

Please sign in to comment.