mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-05 04:38:10 +08:00
PL-5393 Category attribute code should be unique for the certain entity type
#PL-5393
This commit is contained in:
parent
e287725c0a
commit
0ef9872c0e
@ -669,8 +669,9 @@ create table SYS_CATEGORY_ATTR(
|
|||||||
DELETE_TS timestamp,
|
DELETE_TS timestamp,
|
||||||
DELETED_BY varchar(50),
|
DELETED_BY varchar(50),
|
||||||
--
|
--
|
||||||
|
CATEGORY_ENTITY_TYPE varchar(4000),
|
||||||
NAME varchar(255),
|
NAME varchar(255),
|
||||||
CODE varchar(50),
|
CODE varchar(50) not null,
|
||||||
CATEGORY_ID varchar(36),
|
CATEGORY_ID varchar(36),
|
||||||
IS_ENTITY boolean,
|
IS_ENTITY boolean,
|
||||||
DATA_TYPE varchar(200),
|
DATA_TYPE varchar(200),
|
||||||
@ -691,6 +692,8 @@ create table SYS_CATEGORY_ATTR(
|
|||||||
primary key (ID)
|
primary key (ID)
|
||||||
)^
|
)^
|
||||||
|
|
||||||
|
create unique index IDX_CAT_ATTR_ENT_TYPE_AND_CODE on SYS_CATEGORY_ATTR (CATEGORY_ENTITY_TYPE, CODE, DELETE_TS);
|
||||||
|
|
||||||
alter table SYS_CATEGORY_ATTR add constraint SYS_CATEGORY_ATTR_CATEGORY_ID foreign key (CATEGORY_ID) references SYS_CATEGORY(ID)^
|
alter table SYS_CATEGORY_ATTR add constraint SYS_CATEGORY_ATTR_CATEGORY_ID foreign key (CATEGORY_ID) references SYS_CATEGORY(ID)^
|
||||||
|
|
||||||
create table SYS_ATTR_VALUE (
|
create table SYS_ATTR_VALUE (
|
||||||
|
@ -725,8 +725,9 @@ create table SYS_CATEGORY_ATTR (
|
|||||||
DELETE_TS datetime,
|
DELETE_TS datetime,
|
||||||
DELETED_BY varchar(50),
|
DELETED_BY varchar(50),
|
||||||
--
|
--
|
||||||
|
CATEGORY_ENTITY_TYPE varchar(4000),
|
||||||
NAME varchar(255),
|
NAME varchar(255),
|
||||||
CODE varchar(50),
|
CODE varchar(50) not null,
|
||||||
CATEGORY_ID uniqueidentifier,
|
CATEGORY_ID uniqueidentifier,
|
||||||
IS_ENTITY tinyint,
|
IS_ENTITY tinyint,
|
||||||
DATA_TYPE varchar(200),
|
DATA_TYPE varchar(200),
|
||||||
@ -749,7 +750,7 @@ create table SYS_CATEGORY_ATTR (
|
|||||||
)^
|
)^
|
||||||
|
|
||||||
create clustered index IDX_SYS_CATEGORY_ATTR_CATEGORY on SYS_CATEGORY_ATTR (CATEGORY_ID)^
|
create clustered index IDX_SYS_CATEGORY_ATTR_CATEGORY on SYS_CATEGORY_ATTR (CATEGORY_ID)^
|
||||||
|
create unique index IDX_CAT_ATTR_ENT_TYPE_AND_CODE on SYS_CATEGORY_ATTR (CATEGORY_ENTITY_TYPE, CODE, DELETE_TS);
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
create table SYS_ATTR_VALUE (
|
create table SYS_ATTR_VALUE (
|
||||||
|
@ -56,8 +56,9 @@ create table SYS_CATEGORY_ATTR (
|
|||||||
UPDATED_BY varchar2(50),
|
UPDATED_BY varchar2(50),
|
||||||
DELETE_TS timestamp,
|
DELETE_TS timestamp,
|
||||||
DELETED_BY varchar2(50),
|
DELETED_BY varchar2(50),
|
||||||
|
CATEGORY_ENTITY_TYPE varchar(4000),
|
||||||
NAME varchar2(255),
|
NAME varchar2(255),
|
||||||
CODE varchar2(50),
|
CODE varchar2(50) not null,
|
||||||
CATEGORY_ID varchar2(32),
|
CATEGORY_ID varchar2(32),
|
||||||
IS_ENTITY char(1),
|
IS_ENTITY char(1),
|
||||||
DATA_TYPE varchar2(200),
|
DATA_TYPE varchar2(200),
|
||||||
@ -77,6 +78,7 @@ create table SYS_CATEGORY_ATTR (
|
|||||||
primary key(ID)
|
primary key(ID)
|
||||||
)^
|
)^
|
||||||
create index IDX_SYS_CATEGORY_ATTR_CATEGORY on SYS_CATEGORY_ATTR(CATEGORY_ID)^
|
create index IDX_SYS_CATEGORY_ATTR_CATEGORY on SYS_CATEGORY_ATTR(CATEGORY_ID)^
|
||||||
|
create unique index IDX_CAT_ATTR_ENT_TYPE_AND_CODE on SYS_CATEGORY_ATTR (CATEGORY_ENTITY_TYPE, CODE, DELETE_TS);
|
||||||
|
|
||||||
create table SYS_CONFIG (
|
create table SYS_CONFIG (
|
||||||
ID varchar2(32) not null,
|
ID varchar2(32) not null,
|
||||||
|
@ -693,8 +693,9 @@ create table SYS_CATEGORY_ATTR (
|
|||||||
DELETE_TS timestamp,
|
DELETE_TS timestamp,
|
||||||
DELETED_BY varchar(50),
|
DELETED_BY varchar(50),
|
||||||
--
|
--
|
||||||
|
CATEGORY_ENTITY_TYPE varchar(4000),
|
||||||
NAME varchar(255),
|
NAME varchar(255),
|
||||||
CODE varchar(50),
|
CODE varchar(50) not null,
|
||||||
CATEGORY_ID uuid,
|
CATEGORY_ID uuid,
|
||||||
IS_ENTITY boolean,
|
IS_ENTITY boolean,
|
||||||
DATA_TYPE varchar(200),
|
DATA_TYPE varchar(200),
|
||||||
@ -717,6 +718,7 @@ create table SYS_CATEGORY_ATTR (
|
|||||||
)^
|
)^
|
||||||
|
|
||||||
create index IDX_SYS_CATEGORY_ATTR_CATEGORY on SYS_CATEGORY_ATTR (CATEGORY_ID)^
|
create index IDX_SYS_CATEGORY_ATTR_CATEGORY on SYS_CATEGORY_ATTR (CATEGORY_ID)^
|
||||||
|
create unique index IDX_CAT_ATTR_ENT_TYPE_AND_CODE on SYS_CATEGORY_ATTR (CATEGORY_ENTITY_TYPE, CODE) where DELETE_TS is null;
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
create table SYS_ATTR_VALUE (
|
create table SYS_ATTR_VALUE (
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
-- $Id$
|
||||||
|
alter table SYS_CATEGORY_ATTR add column CATEGORY_ENTITY_TYPE varchar(4000);
|
||||||
|
update SYS_CATEGORY_ATTR set CODE = NAME where CODE is null;
|
||||||
|
update SYS_CATEGORY_ATTR attr set CATEGORY_ENTITY_TYPE = (select cat.ENTITY_TYPE from SYS_CATEGORY cat where cat.ID = attr.CATEGORY_ID);
|
||||||
|
alter table SYS_CATEGORY_ATTR alter column CODE set not null;
|
||||||
|
create unique index IDX_CAT_ATTR_ENT_TYPE_AND_CODE on SYS_CATEGORY_ATTR (CATEGORY_ENTITY_TYPE, CODE, DELETE_TS);
|
@ -0,0 +1,6 @@
|
|||||||
|
-- $Id$
|
||||||
|
alter table SYS_CATEGORY_ATTR add column CATEGORY_ENTITY_TYPE varchar(4000);
|
||||||
|
update SYS_CATEGORY_ATTR set CODE = NAME where CODE is null;
|
||||||
|
update SYS_CATEGORY_ATTR attr set CATEGORY_ENTITY_TYPE = (select cat.ENTITY_TYPE from SYS_CATEGORY cat where cat.ID = attr.CATEGORY_ID);
|
||||||
|
alter table SYS_CATEGORY_ATTR alter column CODE set not null;
|
||||||
|
create unique index IDX_CAT_ATTR_ENT_TYPE_AND_CODE on SYS_CATEGORY_ATTR (CATEGORY_ENTITY_TYPE, CODE, DELETE_TS);
|
@ -0,0 +1,6 @@
|
|||||||
|
-- $Id$
|
||||||
|
alter table SYS_CATEGORY_ATTR add column CATEGORY_ENTITY_TYPE varchar(4000);
|
||||||
|
update SYS_CATEGORY_ATTR set CODE = NAME where CODE is null;
|
||||||
|
update SYS_CATEGORY_ATTR attr set CATEGORY_ENTITY_TYPE = (select cat.ENTITY_TYPE from SYS_CATEGORY cat where cat.ID = attr.CATEGORY_ID);
|
||||||
|
alter table SYS_CATEGORY_ATTR alter column CODE set not null;
|
||||||
|
create unique index IDX_CAT_ATTR_ENT_TYPE_AND_CODE on SYS_CATEGORY_ATTR (CATEGORY_ENTITY_TYPE, CODE, DELETE_TS);
|
@ -0,0 +1,6 @@
|
|||||||
|
-- $Id$
|
||||||
|
alter table SYS_CATEGORY_ATTR add column CATEGORY_ENTITY_TYPE varchar(4000);
|
||||||
|
update SYS_CATEGORY_ATTR set CODE = NAME where CODE is null;
|
||||||
|
update SYS_CATEGORY_ATTR attr set CATEGORY_ENTITY_TYPE = (select cat.ENTITY_TYPE from SYS_CATEGORY cat where cat.ID = attr.CATEGORY_ID);
|
||||||
|
alter table SYS_CATEGORY_ATTR alter column CODE set not null;
|
||||||
|
create unique index IDX_CAT_ATTR_ENT_TYPE_AND_CODE on SYS_CATEGORY_ATTR (CATEGORY_ENTITY_TYPE, CODE) where DELETE_TS is null;
|
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2015 Haulmont. All rights reserved.
|
||||||
|
* Use is subject to license terms, see http://www.cuba-platform.com/license for details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.haulmont.cuba.core.app.dynamicattributes;
|
||||||
|
|
||||||
|
import com.haulmont.cuba.core.entity.CategoryAttribute;
|
||||||
|
import com.haulmont.cuba.core.listener.BeforeInsertEntityListener;
|
||||||
|
import com.haulmont.cuba.core.listener.BeforeUpdateEntityListener;
|
||||||
|
|
||||||
|
import javax.annotation.ManagedBean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author degtyarjov
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
@ManagedBean("report_CategoryAttributeListener")
|
||||||
|
public class CategoryAttributeListener
|
||||||
|
implements BeforeInsertEntityListener<CategoryAttribute>, BeforeUpdateEntityListener<CategoryAttribute> {
|
||||||
|
@Override
|
||||||
|
public void onBeforeInsert(CategoryAttribute entity) {
|
||||||
|
setCategoryEntityType(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBeforeUpdate(CategoryAttribute entity) {
|
||||||
|
setCategoryEntityType(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setCategoryEntityType(CategoryAttribute entity) {
|
||||||
|
if (entity.getCategory() != null) {
|
||||||
|
entity.setCategoryEntityType(entity.getCategory().getEntityType());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -6,6 +6,7 @@
|
|||||||
package com.haulmont.cuba.core.entity;
|
package com.haulmont.cuba.core.entity;
|
||||||
|
|
||||||
import com.haulmont.chile.core.annotations.NamePattern;
|
import com.haulmont.chile.core.annotations.NamePattern;
|
||||||
|
import com.haulmont.cuba.core.entity.annotation.Listeners;
|
||||||
import com.haulmont.cuba.core.entity.annotation.SystemLevel;
|
import com.haulmont.cuba.core.entity.annotation.SystemLevel;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.openjpa.persistence.Persistent;
|
import org.apache.openjpa.persistence.Persistent;
|
||||||
@ -18,6 +19,7 @@ import java.util.*;
|
|||||||
@Table(name = "SYS_CATEGORY_ATTR")
|
@Table(name = "SYS_CATEGORY_ATTR")
|
||||||
@NamePattern("%s|name")
|
@NamePattern("%s|name")
|
||||||
@SystemLevel
|
@SystemLevel
|
||||||
|
@Listeners("report_CategoryAttributeListener")
|
||||||
public class CategoryAttribute extends StandardEntity {
|
public class CategoryAttribute extends StandardEntity {
|
||||||
|
|
||||||
private static final long serialVersionUID = -6959392628534815752L;
|
private static final long serialVersionUID = -6959392628534815752L;
|
||||||
@ -29,6 +31,9 @@ public class CategoryAttribute extends StandardEntity {
|
|||||||
@JoinColumn(name = "CATEGORY_ID")
|
@JoinColumn(name = "CATEGORY_ID")
|
||||||
private Category category;
|
private Category category;
|
||||||
|
|
||||||
|
@Column(name = "CATEGORY_ENTITY_TYPE")
|
||||||
|
private String categoryEntityType;
|
||||||
|
|
||||||
@Column(name = "NAME", length = NAME_FIELD_LENGTH, nullable = false)
|
@Column(name = "NAME", length = NAME_FIELD_LENGTH, nullable = false)
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@ -238,6 +243,14 @@ public class CategoryAttribute extends StandardEntity {
|
|||||||
this.targetScreens = targetScreens;
|
this.targetScreens = targetScreens;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getCategoryEntityType() {
|
||||||
|
return categoryEntityType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCategoryEntityType(String categoryEntityType) {
|
||||||
|
this.categoryEntityType = categoryEntityType;
|
||||||
|
}
|
||||||
|
|
||||||
public Set<String> targetScreensSet(){
|
public Set<String> targetScreensSet(){
|
||||||
if (StringUtils.isNotBlank(targetScreens)) {
|
if (StringUtils.isNotBlank(targetScreens)) {
|
||||||
return new HashSet<>(Arrays.asList(targetScreens.split(",")));
|
return new HashSet<>(Arrays.asList(targetScreens.split(",")));
|
||||||
|
@ -307,5 +307,6 @@ IDX_SEC_ROLE_UNIQ_NAME=A role with the same name already exists
|
|||||||
IDX_SEC_USER_UNIQ_LOGIN=A user with the same login already exists
|
IDX_SEC_USER_UNIQ_LOGIN=A user with the same login already exists
|
||||||
IDX_SEC_USER_ROLE_UNIQ_ROLE=The user already has this role
|
IDX_SEC_USER_ROLE_UNIQ_ROLE=The user already has this role
|
||||||
IDX_SEC_PERMISSION_UNIQUE=A permission with the same role, permission type and target already exists
|
IDX_SEC_PERMISSION_UNIQUE=A permission with the same role, permission type and target already exists
|
||||||
|
IDX_CAT_ATTR_ENT_TYPE_AND_CODE=An attribute with the same code already exists for the entity type
|
||||||
|
|
||||||
LoginException.InvalidLoginOrPassword=Unknown login name or bad password: %s
|
LoginException.InvalidLoginOrPassword=Unknown login name or bad password: %s
|
@ -298,5 +298,6 @@ IDX_SYS_SCHEDULED_TASK_UNIQ_BEAN_METHOD=Задача с такими bean name,
|
|||||||
IDX_SEC_ROLE_UNIQ_NAME=Роль с таким именем уже существует
|
IDX_SEC_ROLE_UNIQ_NAME=Роль с таким именем уже существует
|
||||||
IDX_SEC_USER_UNIQ_LOGIN=Пользователь с таким логином уже существует
|
IDX_SEC_USER_UNIQ_LOGIN=Пользователь с таким логином уже существует
|
||||||
IDX_SEC_USER_ROLE_UNIQ_ROLE=У пользователя уже есть эта роль
|
IDX_SEC_USER_ROLE_UNIQ_ROLE=У пользователя уже есть эта роль
|
||||||
|
IDX_CAT_ATTR_ENT_TYPE_AND_CODE=Динамический атрибут с таким кодом уже задан для данного типа сущности
|
||||||
|
|
||||||
LoginException.InvalidLoginOrPassword=Неверный логин или пароль: %s
|
LoginException.InvalidLoginOrPassword=Неверный логин или пароль: %s
|
Loading…
Reference in New Issue
Block a user