Skip to content

Commit

Permalink
KAA-25: Changed profile filter model and dto objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Khanenko committed Dec 11, 2015
1 parent 7c4c965 commit 52ab163
Show file tree
Hide file tree
Showing 19 changed files with 180 additions and 173 deletions.
Expand Up @@ -171,7 +171,8 @@ public class DaoConstants {
*/ */
public static final String PROFILE_FILTER_TABLE_NAME = "profile_filter"; public static final String PROFILE_FILTER_TABLE_NAME = "profile_filter";
public static final String PROFILE_FILTER_BODY = "profile_filter_body"; public static final String PROFILE_FILTER_BODY = "profile_filter_body";
public static final String PROFILE_FILTER_SCHEMA_ID = SCHEMA_ID; public static final String PROFILE_FILTER_ENDPOINT_SCHEMA_ID = "endpoint_schema_id";
public static final String PROFILE_FILTER_SERVER_SCHEMA_ID = "endpoint_schema_id";


/** /**
* Endpoint group constants. * Endpoint group constants.
Expand Down
Expand Up @@ -88,10 +88,11 @@ public interface ProfileService {
Collection<StructureRecordDto<ProfileFilterDto>> findAllProfileFilterRecordsByEndpointGroupId(String endpointGroupId, boolean includeDeprecated); Collection<StructureRecordDto<ProfileFilterDto>> findAllProfileFilterRecordsByEndpointGroupId(String endpointGroupId, boolean includeDeprecated);


/** /**
* Find profile filter record by schema id and endpoint group id. * Find profile filter record by schema ids and endpoint group id.
* *
* @param schemaId the schema id * @param endpointProfileSchemaId the endpoint profile schema identifier
* @param endpointGroupId the endpoint group id * @param serverProfileSchemaId the server profile schema identifier
* @param endpointGroupId the endpoint group identifier
* @return the structure record dto * @return the structure record dto
*/ */
StructureRecordDto<ProfileFilterDto> findProfileFilterRecordBySchemaIdAndEndpointGroupId(String endpointProfileSchemaId, String serverProfileSchemaId, String endpointGroupId); StructureRecordDto<ProfileFilterDto> findProfileFilterRecordBySchemaIdAndEndpointGroupId(String endpointProfileSchemaId, String serverProfileSchemaId, String endpointGroupId);
Expand Down Expand Up @@ -141,7 +142,8 @@ public interface ProfileService {
/** /**
* Delete profile filter record. * Delete profile filter record.
* *
* @param schemaId the profile schema id * @param endpointProfileSchemaId the profile schema id
* @param serverProfileSchemaId the server profile schema id
* @param groupId the endpoint group id * @param groupId the endpoint group id
* @param deactivatedUsername the deactivated username * @param deactivatedUsername the deactivated username
* @return the change profile filter notification * @return the change profile filter notification
Expand All @@ -152,10 +154,11 @@ public interface ProfileService {
* Find profile filter by application id and version. * Find profile filter by application id and version.
* *
* @param appId the application id * @param appId the application id
* @param schemaVersion the schema version * @param endpointSchemaVersion the schema version
* @param serverSchemaVersion the schema version
* @return the list of profile filters * @return the list of profile filters
*/ */
List<ProfileFilterDto> findProfileFiltersByAppIdAndVersions(String appId, int clientSchemaVersion, int serverSchemaVersion); List<ProfileFilterDto> findProfileFiltersByAppIdAndVersions(String appId, int endpointSchemaVersion, int serverSchemaVersion);


/** /**
* Find profile schema by application id and version. * Find profile schema by application id and version.
Expand All @@ -168,8 +171,9 @@ public interface ProfileService {


/** /**
* Find profile filter by profile schema id and endpoint group id. * Find profile filter by profile schema id and endpoint group id.
* @param schemaId the profile schema id * @param endpointProfileSchemaId the endpoint profile schema identifier
* @param groupId the endpoint group id * @param serverProfileSchemaId the server profile schema identifier
* @param groupId the endpoint group identifier
* @return found profile filter * @return found profile filter
*/ */
ProfileFilterDto findLatestFilterBySchemaIdsAndGroupId(String endpointProfileSchemaId, String serverProfileSchemaId, String groupId); ProfileFilterDto findLatestFilterBySchemaIdsAndGroupId(String endpointProfileSchemaId, String serverProfileSchemaId, String groupId);
Expand Down
Expand Up @@ -28,10 +28,11 @@ public interface ProfileFilterDao<T> extends SqlDao<T> {
/** /**
* Find all profile filters by profile schema id * Find all profile filters by profile schema id
* *
* @param profileSchemaId the profile schema id * @param endpointProfileSchemaId the endpoint profile schema id
* @param serverProfileSchemaId the server profile schema id
* @return the list of profile schemas * @return the list of profile schemas
*/ */
List<T> findAllByProfileSchemaId(String profileSchemaId); List<T> findAllByProfileSchemaId(String endpointProfileSchemaId, String serverProfileSchemaId);


/** /**
* Find actual profile filters by endpoint group id. * Find actual profile filters by endpoint group id.
Expand Down Expand Up @@ -70,10 +71,10 @@ public interface ProfileFilterDao<T> extends SqlDao<T> {
* Find profile filters by application and schema version. * Find profile filters by application and schema version.
* *
* @param appId the application id * @param appId the application id
* @param schemaVersion the schema version * @param endpointSchemaVersion
* @return the list of profile filters * @return the list of profile filters
*/ */
List<T> findByAppIdAndSchemaVersion(String appId, int schemaVersion); List<T> findByAppIdAndSchemaVersions(String appId, int endpointSchemaVersion, int serverSchemaVersion);


/** /**
* Find inactive profile filters. * Find inactive profile filters.
Expand Down
Expand Up @@ -140,19 +140,19 @@ public void removeByEndpointGroupId(String groupId) {
} }


@Override @Override
public List<ProfileFilter> findByAppIdAndSchemaVersion(String appId, int schemaVersion) { public List<ProfileFilter> findByAppIdAndSchemaVersions(String appId, int endpointSchemaVersion, int serverSchemaVersion) {
List<ProfileFilter> filters = null; List<ProfileFilter> filters = null;
LOG.debug("Searching configuration by application id [{}] and schema version [{}]", appId, schemaVersion); LOG.debug("Searching configuration by application id [{}] and schema version [{}]", appId, serverSchemaVersion);
if (isNotBlank(appId)) { if (isNotBlank(appId)) {
filters = findListByCriterionWithAlias(APPLICATION_PROPERTY, APPLICATION_ALIAS, Restrictions.and( filters = findListByCriterionWithAlias(APPLICATION_PROPERTY, APPLICATION_ALIAS, Restrictions.and(
Restrictions.eq(APPLICATION_REFERENCE, Long.valueOf(appId)), Restrictions.eq(APPLICATION_REFERENCE, Long.valueOf(appId)),
Restrictions.eq(SCHEMA_VERSION_PROPERTY, schemaVersion), Restrictions.eq(SCHEMA_VERSION_PROPERTY, serverSchemaVersion),
Restrictions.eq(STATUS_PROPERTY, UpdateStatus.ACTIVE))); Restrictions.eq(STATUS_PROPERTY, UpdateStatus.ACTIVE)));
} }
if (LOG.isTraceEnabled()) { if (LOG.isTraceEnabled()) {
LOG.trace("[{},{}] Search result: {}.", appId, schemaVersion, Arrays.toString(filters.toArray())); LOG.trace("[{},{}] Search result: {}.", appId, serverSchemaVersion, Arrays.toString(filters.toArray()));
} else { } else {
LOG.debug("[{},{}] Search result: {}.", appId, schemaVersion, filters.size()); LOG.debug("[{},{}] Search result: {}.", appId, serverSchemaVersion, filters.size());
} }
return filters; return filters;
} }
Expand Down
Expand Up @@ -19,7 +19,7 @@
import org.hibernate.criterion.Order; import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions; import org.hibernate.criterion.Restrictions;
import org.kaaproject.kaa.server.common.dao.impl.ProfileSchemaDao; import org.kaaproject.kaa.server.common.dao.impl.ProfileSchemaDao;
import org.kaaproject.kaa.server.common.dao.model.sql.ProfileSchema; import org.kaaproject.kaa.server.common.dao.model.sql.EndpointProfileSchema;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
Expand All @@ -36,13 +36,13 @@
import static org.kaaproject.kaa.server.common.dao.DaoConstants.VERSION_PROPERTY; import static org.kaaproject.kaa.server.common.dao.DaoConstants.VERSION_PROPERTY;


@Repository @Repository
public class HibernateProfileSchemaDao extends HibernateAbstractDao<ProfileSchema> implements ProfileSchemaDao<ProfileSchema> { public class HibernateProfileSchemaDao extends HibernateAbstractDao<EndpointProfileSchema> implements ProfileSchemaDao<EndpointProfileSchema> {


private static final Logger LOG = LoggerFactory.getLogger(HibernateProfileSchemaDao.class); private static final Logger LOG = LoggerFactory.getLogger(HibernateProfileSchemaDao.class);


@Override @Override
public List<ProfileSchema> findByApplicationId(String appId) { public List<EndpointProfileSchema> findByApplicationId(String appId) {
List<ProfileSchema> schemas = Collections.emptyList(); List<EndpointProfileSchema> schemas = Collections.emptyList();
LOG.debug("Searching profile schemas by application id [{}] ", appId); LOG.debug("Searching profile schemas by application id [{}] ", appId);
if (isNotBlank(appId)) { if (isNotBlank(appId)) {
schemas = findListByCriterionWithAlias(APPLICATION_PROPERTY, APPLICATION_ALIAS, schemas = findListByCriterionWithAlias(APPLICATION_PROPERTY, APPLICATION_ALIAS,
Expand All @@ -57,9 +57,9 @@ public List<ProfileSchema> findByApplicationId(String appId) {
} }


@Override @Override
public ProfileSchema findByAppIdAndVersion(String appId, int version) { public EndpointProfileSchema findByAppIdAndVersion(String appId, int version) {
LOG.debug("Searching profile schema by application id [{}] and version [{}]", appId, version); LOG.debug("Searching profile schema by application id [{}] and version [{}]", appId, version);
ProfileSchema schema = null; EndpointProfileSchema schema = null;
if (isNotBlank(appId)) { if (isNotBlank(appId)) {
schema = findOneByCriterionWithAlias(APPLICATION_PROPERTY, APPLICATION_ALIAS, Restrictions.and( schema = findOneByCriterionWithAlias(APPLICATION_PROPERTY, APPLICATION_ALIAS, Restrictions.and(
Restrictions.eq(APPLICATION_REFERENCE, Long.valueOf(appId)), Restrictions.eq(APPLICATION_REFERENCE, Long.valueOf(appId)),
Expand All @@ -74,8 +74,8 @@ public ProfileSchema findByAppIdAndVersion(String appId, int version) {
} }


@Override @Override
public ProfileSchema findLatestByAppId(String appId) { public EndpointProfileSchema findLatestByAppId(String appId) {
ProfileSchema latestSchema = null; EndpointProfileSchema latestSchema = null;
LOG.debug("Searching latest profile schema by application id [{}] ", appId); LOG.debug("Searching latest profile schema by application id [{}] ", appId);
if (isNotBlank(appId)) { if (isNotBlank(appId)) {
Criteria criteria = getCriteria().createAlias(APPLICATION_PROPERTY, APPLICATION_ALIAS) Criteria criteria = getCriteria().createAlias(APPLICATION_PROPERTY, APPLICATION_ALIAS)
Expand All @@ -92,9 +92,9 @@ public ProfileSchema findLatestByAppId(String appId) {
} }


@Override @Override
public List<ProfileSchema> findVacantSchemas(String appId, List<String> usedSchemaIds) { public List<EndpointProfileSchema> findVacantSchemas(String appId, List<String> usedSchemaIds) {
LOG.debug("Searching vacant schemas by application id [{}] and used schema ids [{}] ", appId, usedSchemaIds); LOG.debug("Searching vacant schemas by application id [{}] and used schema ids [{}] ", appId, usedSchemaIds);
List<ProfileSchema> schemas = Collections.emptyList(); List<EndpointProfileSchema> schemas = Collections.emptyList();
if (isNotBlank(appId)) { if (isNotBlank(appId)) {
Criteria criteria = getCriteria().createAlias(APPLICATION_PROPERTY, APPLICATION_ALIAS) Criteria criteria = getCriteria().createAlias(APPLICATION_PROPERTY, APPLICATION_ALIAS)
.add(Restrictions.eq(APPLICATION_REFERENCE, Long.valueOf(appId))); .add(Restrictions.eq(APPLICATION_REFERENCE, Long.valueOf(appId)));
Expand All @@ -112,7 +112,7 @@ public List<ProfileSchema> findVacantSchemas(String appId, List<String> usedSche
} }


@Override @Override
protected Class<ProfileSchema> getEntityClass() { protected Class<EndpointProfileSchema> getEntityClass() {
return ProfileSchema.class; return EndpointProfileSchema.class;
} }
} }
Expand Up @@ -28,18 +28,18 @@
@Entity @Entity
@Table(name = PROFILE_SCHEMA_TABLE_NAME) @Table(name = PROFILE_SCHEMA_TABLE_NAME)
@OnDelete(action = OnDeleteAction.CASCADE) @OnDelete(action = OnDeleteAction.CASCADE)
public final class ProfileSchema extends BaseSchema<EndpointProfileSchemaDto> implements Serializable { public final class EndpointProfileSchema extends BaseSchema<EndpointProfileSchemaDto> implements Serializable {


private static final long serialVersionUID = 953188575107921799L; private static final long serialVersionUID = 953188575107921799L;


public ProfileSchema() { public EndpointProfileSchema() {
} }


public ProfileSchema(Long id) { public EndpointProfileSchema(Long id) {
setId(id); setId(id);
} }


public ProfileSchema(EndpointProfileSchemaDto dto) { public EndpointProfileSchema(EndpointProfileSchemaDto dto) {
super(dto); super(dto);
} }


Expand All @@ -49,7 +49,7 @@ protected EndpointProfileSchemaDto createDto() {
} }


@Override @Override
protected GenericModel<ProfileSchemaDto> newInstance(Long id) { protected GenericModel<EndpointProfileSchemaDto> newInstance(Long id) {
return new ProfileSchema(id); return new EndpointProfileSchema(id);
} }
} }
Expand Up @@ -94,6 +94,15 @@ public static Set<Topic> getTopic(List<String> topicIds) {
return topics; return topics;
} }


public static <V extends GenericModel> V getGenericModelWithId(HasId hasId, V model) {
if (hasId == null) {
model.setId(getLongId(hasId));
return model;
} else {
return null;
}
}

public static <V> Set<V> getGenericModelIdds(Set<String> idSet, GenericModel model) { public static <V> Set<V> getGenericModelIdds(Set<String> idSet, GenericModel model) {
Set<V> dataSet = new HashSet<>(); Set<V> dataSet = new HashSet<>();
for (String id : idSet) { for (String id : idSet) {
Expand Down
Expand Up @@ -22,17 +22,15 @@
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany; import javax.persistence.ManyToOne;
import javax.persistence.Table; import javax.persistence.Table;
import java.io.Serializable; import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;


import static org.kaaproject.kaa.server.common.dao.DaoConstants.PROFILE_FILTER_BODY; import static org.kaaproject.kaa.server.common.dao.DaoConstants.PROFILE_FILTER_BODY;
import static org.kaaproject.kaa.server.common.dao.DaoConstants.PROFILE_FILTER_SCHEMA_ID; import static org.kaaproject.kaa.server.common.dao.DaoConstants.PROFILE_FILTER_ENDPOINT_SCHEMA_ID;
import static org.kaaproject.kaa.server.common.dao.DaoConstants.PROFILE_FILTER_SERVER_SCHEMA_ID;
import static org.kaaproject.kaa.server.common.dao.DaoConstants.PROFILE_FILTER_TABLE_NAME; import static org.kaaproject.kaa.server.common.dao.DaoConstants.PROFILE_FILTER_TABLE_NAME;
import static org.kaaproject.kaa.server.common.dao.model.sql.ModelUtils.getGenericModelIdds; import static org.kaaproject.kaa.server.common.dao.model.sql.ModelUtils.getGenericModelWithId;
import static org.kaaproject.kaa.server.common.dao.model.sql.ModelUtils.getGenericModelVersions;


@Entity @Entity
@Table(name = PROFILE_FILTER_TABLE_NAME) @Table(name = PROFILE_FILTER_TABLE_NAME)
Expand All @@ -44,12 +42,12 @@ public final class ProfileFilter extends AbstractStructure<ProfileFilterDto> imp
@Column(name = PROFILE_FILTER_BODY) @Column(name = PROFILE_FILTER_BODY)
private String body; private String body;


@ManyToMany @ManyToOne
@JoinColumn(name = PROFILE_FILTER_SCHEMA_ID, nullable = false) @JoinColumn(name = PROFILE_FILTER_ENDPOINT_SCHEMA_ID, nullable = false)
private Set<ProfileSchema> profileSchemas = new HashSet<>(); private EndpointProfileSchema endpointProfileSchema;
@ManyToMany @ManyToOne
@JoinColumn(name = PROFILE_FILTER_SCHEMA_ID, nullable = false) @JoinColumn(name = PROFILE_FILTER_SERVER_SCHEMA_ID, nullable = false)
private Set<ServerProfileSchema> serverProfileSchemas = new HashSet<>(); private ServerProfileSchema serverProfileSchema;


public ProfileFilter() { public ProfileFilter() {
} }
Expand All @@ -61,6 +59,8 @@ public ProfileFilter(Long id) {
public ProfileFilter(ProfileFilterDto dto) { public ProfileFilter(ProfileFilterDto dto) {
super(dto); super(dto);
this.body = dto.getBody(); this.body = dto.getBody();
this.endpointProfileSchema = getGenericModelWithId(dto, new EndpointProfileSchema());
this.serverProfileSchema = getGenericModelWithId(dto, new ServerProfileSchema());
} }


@Override @Override
Expand All @@ -87,14 +87,19 @@ protected GenericModel<ProfileFilterDto> newInstance(Long id) {
public ProfileFilterDto toDto() { public ProfileFilterDto toDto() {
ProfileFilterDto filterDto = super.toDto(); ProfileFilterDto filterDto = super.toDto();
filterDto.setBody(body); filterDto.setBody(body);
filterDto.setEndpointSchemaVersions(getGenericModelVersions(profileSchemas)); if (endpointProfileSchema != null) {
filterDto.setServerSchemaVersions(getGenericModelVersions(serverProfileSchemas)); filterDto.setEndpointProfileSchemaId(endpointProfileSchema.getStringId());
filterDto.setEndpointProfileSchemaVersion(endpointProfileSchema.getVersion());
}
if (serverProfileSchema != null) {
filterDto.setServerProfileSchemaId(serverProfileSchema.getStringId());
filterDto.setServerProfileSchemaVersion(serverProfileSchema.getVersion());
}
return filterDto; return filterDto;
} }


public String getGroupId() { public String getGroupId() {
return endpointGroup.getStringId(); return endpointGroup.getStringId();
} }



} }

0 comments on commit 52ab163

Please sign in to comment.