Skip to content

Commit

Permalink
Merge pull request #1171 from WeBankPartners/dev
Browse files Browse the repository at this point in the history
release v1.5.5
  • Loading branch information
gavin2lee authored Dec 1, 2020
2 parents 10f14c2 + d5fd190 commit 307fd70
Show file tree
Hide file tree
Showing 11 changed files with 198 additions and 39 deletions.
2 changes: 1 addition & 1 deletion build/start.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
mkdir -p /log
mkdir -p /data/wecmdb/log

JAVA_OPT="-verbose:gc -Xloggc:/data/wecmdb/log/wecmdb_gc_%p.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCApplicationStoppedTime -XX:+PrintAdaptiveSizePolicy"
JAVA_OPT="${JAVA_OPT} -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=30m"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1836,9 +1836,15 @@ public List<Map<String, Object>> updateCiDataForPassword(int ciTypeId, Map<Strin
// if(param.get("originalValue")==null||ciDataMap.get(param.get("field"))==null) {
// throw new CmdbException("3052","Password is null");
// }
if(!param.get("originalValue").toString().equals(ciDataMap.get(param.get("field")).toString())) {
throw new CmdbException("3053", String.format("Password mistake"));

if(!StringUtils.isBlank(dbOriginalValue)){
if(!dbOriginalValue.equals(paramOriginalValue)){
throw new CmdbException("3053", String.format("Password mistake"));
}
}
// if(!param.get("originalValue").toString().equals(ciDataMap.get(param.get("field")).toString())) {
// throw new CmdbException("3053", String.format("Password mistake"));
// }
return ciService.update(ciTypeId, Arrays.asList(data));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ List<AdmCiTypeAttr> findByInputTypeAndReferenceIdAndStatusAndIsDeleteValidate(St
List<AdmCiTypeAttr> findAllByFilterRuleNotNull();


@Cacheable(value="admCiTypeAttrRepository-getSortedMapForMultiRef",key = "#attr.idAdmCiTypeAttr")
default Map<String, Integer> getSortedMapForMultiRef(EntityManager entityManager, AdmCiTypeAttr attr, DynamicEntityMeta multRefMeta) {
Map<String, Integer> sortMap = new HashMap<>();
String joinTable = attr.retrieveJoinTalbeName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,7 @@

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.Stack;
import java.util.TimeZone;
import java.util.*;
import java.util.stream.Collectors;

import javax.persistence.*;
Expand Down Expand Up @@ -368,12 +356,16 @@ public QueryResponse<CiData> query(int ciTypeId, QueryRequest ciRequest) {
logger.info("[Performance measure][query] Elapsed time in doing query: {}",stopwatch.toString());

stopwatch.reset().start();

Map<Integer, AdmCiTypeAttr> attrMap = getIntegerAdmCiTypeAttrMap(entityMeta.getCiTypeId());
Map<Integer,Map<String, Integer>> multiSortCiMap = getMltiSortedCIMap(entityMeta, entityManager, attrMap);

results.forEach(x -> {
Map<String, Object> entityBeanMap = null;

entityBeanMap = ClassUtils.convertBeanToMap(x, entityMeta, true, ciRequest.getResultColumns());

Map<String, Object> enhacedMap = enrichCiObject(entityMeta, entityBeanMap, entityManager);
Map<String, Object> enhacedMap = enrichCiObject(entityMeta, entityBeanMap, entityManager, attrMap, multiSortCiMap);
List<String> nextOperations = getNextOperations(entityBeanMap);
CiData ciData = new CiData(enhacedMap, nextOperations);
if(!(ciData.getData().get(DEFAULT_FIELD_FIXED_DATE) != null && "".equals(ciData.getData().get(DEFAULT_FIELD_FIXED_DATE)) && CIDATA_STATE_DELETED.equals(ciData.getData().get(DEFAULT_FIELD_STATE_CODE)))) {
Expand All @@ -394,6 +386,30 @@ public QueryResponse<CiData> query(int ciTypeId, QueryRequest ciRequest) {
return ciInfoResp;
}

private Map<Integer,Map<String, Integer>> getMltiSortedCIMap(DynamicEntityMeta entityMeta, EntityManager entityManager, Map<Integer, AdmCiTypeAttr> attrMap) {
Map<Integer,Map<String, Integer>> multiSortMap = new HashMap<>();
Collection<FieldNode> fieldNodes = entityMeta.getAllFieldNodes(true);
for (FieldNode fieldNode : fieldNodes) {
if(fieldNode.isJoinNode() && DynamicEntityType.MultiReference.equals(fieldNode.getEntityType()) && Strings.isNullOrEmpty(fieldNode.getMappedBy())) {
Integer attrId = fieldNode.getAttrId();
AdmCiTypeAttr attr = attrMap.get(attrId);
DynamicEntityMeta multRefMeta = multRefMetaMap.get(attrId);
Map<String, Integer> sortMap = ciTypeAttrRepository.getSortedMapForMultiRef(entityManager, attr, multRefMeta);
multiSortMap.put(attrId,sortMap);
}
}
return multiSortMap;
}

private Map<Integer, AdmCiTypeAttr> getIntegerAdmCiTypeAttrMap(Integer ciTypeId) {
List<AdmCiTypeAttr> attrs = ciTypeAttrRepository.findAllByCiTypeId(ciTypeId);
Map<Integer, AdmCiTypeAttr> attrMap = new HashMap<>();
for (AdmCiTypeAttr attr : attrs) {
attrMap.put(attr.getIdAdmCiTypeAttr(), attr);
}
return attrMap;
}

private boolean isRefColumnRequested(DynamicEntityMeta entityMeta, QueryRequest ciRequest){
for (FieldNode node : entityMeta.getAllFieldNodes(true)) {
if(isRequestedJoinNode(ciRequest, node)){
Expand Down Expand Up @@ -687,14 +703,9 @@ private Predicate buildAccessControlPredicate(int ciTypeId, CriteriaBuilder crit
return criteriaBuilder.or(rulePredicates);
}

private Map<String, Object> enrichCiObject(DynamicEntityMeta entityMeta, Map<String, Object> ciObjMap, EntityManager entityManager) {
private Map<String, Object> enrichCiObject(DynamicEntityMeta entityMeta, Map<String, Object> ciObjMap, EntityManager entityManager,
Map<Integer, AdmCiTypeAttr> attrMap, Map<Integer,Map<String, Integer>> multiSortCiMap) {
Map<String, Object> ciMap = new HashMap<>();
List<AdmCiTypeAttr> attrs = ciTypeAttrRepository.findAllByCiTypeId(entityMeta.getCiTypeId());

Map<Integer, AdmCiTypeAttr> attrMap = new HashMap<>();
for (AdmCiTypeAttr attr : attrs) {
attrMap.put(attr.getIdAdmCiTypeAttr(), attr);
}

for (Map.Entry kv : ciObjMap.entrySet()) {
String fieldName = kv.getKey().toString();
Expand Down Expand Up @@ -1114,6 +1125,7 @@ public List<Map<String, Object>> update(@CiTypeId int ciTypeId,@CiDataType List<
validateDynamicEntityManager();
List<Map<String, Object>> rtnCis = new LinkedList<>();
List<ExceptionHolder> exceptionHolders = new LinkedList<>();
Map<Integer, AdmCiTypeAttr> attrMap = getIntegerAdmCiTypeAttrMap(ciTypeId);

PriorityEntityManager priEntityManager = getEntityManager();
EntityManager entityManager = priEntityManager.getEntityManager();
Expand All @@ -1138,7 +1150,9 @@ public List<Map<String, Object>> update(@CiTypeId int ciTypeId,@CiDataType List<

Map<String, Object> updatedDomainMap = doUpdate(entityManager, ciTypeId, ci, true);

Map<String, Object> enhacedMap = enrichCiObject(entityMeta, updatedDomainMap, entityManager);
Map<Integer,Map<String, Integer>> multiSortCiMap = getMltiSortedCIMap(entityMeta, entityManager, attrMap);
Map<String, Object> enhacedMap = enrichCiObject(entityMeta, updatedDomainMap, entityManager,
attrMap,multiSortCiMap);

enhacedMap.put(CALLBACK_ID, callbackId);
rtnCis.add(enhacedMap);
Expand Down Expand Up @@ -2297,9 +2311,13 @@ private List<Map<String, Object>> queryWithFilters(int ciTypeId, List<Filter> fi

stopwatch.reset().start();
List<Map<String, Object>> resultList = Lists.newLinkedList();

Map<Integer, AdmCiTypeAttr> attrMap = getIntegerAdmCiTypeAttrMap(entityMeta.getCiTypeId());
Map<Integer,Map<String, Integer>> multiSortCiMap = getMltiSortedCIMap(entityMeta, entityManager, attrMap);

results.forEach(x -> {
Map<String, Object> entityBeanMap = ClassUtils.convertBeanToMap(x, entityMeta, false);
Map<String, Object> enhacedMap = enrichCiObject(entityMeta, entityBeanMap, entityManager);
Map<String, Object> enhacedMap = enrichCiObject(entityMeta, entityBeanMap, entityManager, attrMap,multiSortCiMap);
resultList.add(enhacedMap);
});
stopwatch.stop();
Expand Down Expand Up @@ -2333,7 +2351,10 @@ public List<Map<String, Object>> operateState(@Guid List<CiIndentity> ciIds, Str
ci.put(CmdbConstants.DEFAULT_FIELD_STATE,operation);
ci.put(GUID, ciId);
ciDataInterceptorService.handleReferenceAutoFill(entityHolder,entityManager,ci);
Map<String, Object> enhacedMap = enrichCiObject(entityMeta, result, entityManager);
Map<Integer, AdmCiTypeAttr> attrMap = getIntegerAdmCiTypeAttrMap(entityMeta.getCiTypeId());
Map<Integer,Map<String, Integer>> multiSortCiMap = getMltiSortedCIMap(entityMeta, entityManager, attrMap);

Map<String, Object> enhacedMap = enrichCiObject(entityMeta, result, entityManager,attrMap,multiSortCiMap);
results.add(enhacedMap);
}
transaction.commit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -711,10 +711,14 @@ public void handleReferenceAutoFill(DynamicEntityHolder entityHolder, EntityMana
if (ci.containsKey(attr.getPropertyName())) {
List<AdmCiTypeAttr> attrsWithMatchRule = ciTypeAttrRepository.findAllByMatchAutoFillRule("\\\\\\\"attrId\\\\\\\":" + attr.getIdAdmCiTypeAttr());
attrsWithMatchRule.forEach(attrWithMatchRule -> {
if (attrWithMatchRule.getIsAuto() == CmdbConstants.IS_AUTO_YES) {
logger.info("Executing autofill on matched attr ({}) for attr ({})",attrWithMatchRule.getIdAdmCiTypeAttr(),attr.getIdAdmCiTypeAttr());
executeAutoFill(entityHolder, entityManager, entityHolder.get("guid").toString(), attr, attrWithMatchRule);
}
Integer isAutoFillEnabled = attrWithMatchRule.getIsAuto();
if (!CmdbConstants.IS_AUTO_YES.equals(isAutoFillEnabled)) return;

CiStatus attrCiStatus = CiStatus.fromCode(attrWithMatchRule.getStatus());
if (!attrCiStatus.supportCiDataOperation()) return;

logger.info("Executing autofill on matched attr ({}) for attr ({})",attrWithMatchRule.getIdAdmCiTypeAttr(),attr.getIdAdmCiTypeAttr());
executeAutoFill(entityHolder, entityManager, entityHolder.get("guid").toString(), attr, attrWithMatchRule);
});
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package com.webank.cmdb.service;

import com.google.common.collect.ImmutableMap;
import com.webank.cmdb.constant.CiStatus;
import com.webank.cmdb.controller.AbstractBaseControllerTest;
import com.webank.cmdb.dto.CiTypeAttrDto;
import com.webank.cmdb.dto.CiTypeDto;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import javax.persistence.EntityManager;
import javax.transaction.Transactional;
import java.util.Collections;

public class CiTypeServiceImplTest extends AbstractBaseControllerTest {
@Autowired
CiTypeService ciTypeService;
@Autowired
StaticDtoService staticDtoService;
@Autowired
private EntityManager entityManager;

private int appliedCiTypeId;
private int appliedAttrId;
private int unappliedCiTypeId;
private int refAttrId;

@Transactional
@Test
public void testCreateCiDataShouldIgnoreAutoFillRuleForNotCreatedCiAttr() {
givenAppliedCiTypeAndAttr();
givenUnappliedCiTypeAndRef();
givenAutoFillRuleForUnappliedAttrReferencingAppliedCiAttr();

String guid = ciService.create(appliedCiTypeId, new ImmutableMap.Builder<String, Object>()
.put("code", "code")
.put("appliedAttr", "appliedAttr")
.build());

Assert.assertNotNull(guid);
}

private void givenAppliedCiTypeAndAttr() {
appliedCiTypeId = givenCiType("appliedCiTypeName");
appliedAttrId = givenCiAttrForType(appliedCiTypeId, "appliedAttr", null);
applyCiType(appliedCiTypeId);
}

private void givenUnappliedCiTypeAndRef() {
unappliedCiTypeId = givenCiType("unappliedCiTypeName");
refAttrId = givenCiRefForType(unappliedCiTypeId, "ref", appliedCiTypeId);
}

private void givenAutoFillRuleForUnappliedAttrReferencingAppliedCiAttr() {
String autoFillRuleFromUnappliedCiAttrToAppliedCiType = buildAutoFillRule();
givenCiAttrForType(unappliedCiTypeId, "unappliedAttr", autoFillRuleFromUnappliedCiAttrToAppliedCiType);
}

private int givenCiType(String name) {
CiTypeDto ciTypeDto = new CiTypeDto();
ciTypeDto.setName(name);
ciTypeDto.setTableName(name);
ciTypeDto.setStatus(CiStatus.NotCreated.getCode());

CiTypeDto result = ciTypeService.addCiType(ciTypeDto);
entityManager.clear();

return result.getCiTypeId();
}

private int givenCiAttrForType(int ciTypeId, String name, String autoFillRule) {
CiTypeAttrDto attrDto = new CiTypeAttrDto();
attrDto.setCiTypeId(ciTypeId);
attrDto.setName(name);
attrDto.setPropertyName(name);
attrDto.setStatus(CiStatus.NotCreated.getCode());
attrDto.setInputType("text");
attrDto.setPropertyType("varchar");
attrDto.setLength(32);
attrDto.setIsSystem(false);
attrDto.setIsNullable(true);
attrDto.setIsAuto(autoFillRule != null);
attrDto.setAutoFillRule(autoFillRule);

CiTypeAttrDto result = staticDtoService.create(CiTypeAttrDto.class, Collections.singletonList(attrDto)).get(0);
entityManager.clear();

return result.getCiTypeAttrId();
}

private int givenCiRefForType(int ciTypeId, String name, int referenceTypeId) {
CiTypeAttrDto attrDto = new CiTypeAttrDto();
attrDto.setCiTypeId(ciTypeId);
attrDto.setName(name);
attrDto.setPropertyName(name);
attrDto.setStatus(CiStatus.NotCreated.getCode());
attrDto.setInputType("ref");
attrDto.setPropertyType("varchar");
attrDto.setLength(15);
attrDto.setReferenceId(referenceTypeId);
attrDto.setReferenceType(27);
attrDto.setReferenceName("属于");
attrDto.setIsSystem(false);
attrDto.setIsNullable(true);

CiTypeAttrDto result = staticDtoService.create(CiTypeAttrDto.class, Collections.singletonList(attrDto)).get(0);
entityManager.clear();

return result.getCiTypeAttrId();
}

private void applyCiType(int ciTypeId) {
ciTypeService.applyCiType(Collections.singletonList(ciTypeId));
entityManager.clear();
}

private String buildAutoFillRule() {
return "[{\"type\":\"rule\",\"value\":\"[" +
"{\\\"ciTypeId\\\":" + unappliedCiTypeId + "}," +
"{\\\"ciTypeId\\\":" + appliedCiTypeId + ",\\\"parentRs\\\":{\\\"attrId\\\":" + refAttrId + ",\\\"isReferedFromParent\\\":1}}," +
"{\\\"ciTypeId\\\":" + appliedCiTypeId + ",\\\"parentRs\\\":{\\\"attrId\\\":" + appliedAttrId + ",\\\"isReferedFromParent\\\":1}}" +
"]\"}]";
}
}
2 changes: 1 addition & 1 deletion cmdb-core/src/test/resources/db/data_model.sql
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ INSERT INTO `adm_ci_type_attr_base` (`id_adm_ci_type_attr`, `id_adm_ci_type`, `n
(6, 1, '创建用户', '创建用户', 'text', 'created_by', 'varchar', 50, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0, 1, 0, 0, NULL, 'notCreated', 1, 0, 0, NULL, NULL, 0, 1),
(7, 1, '创建日期', '创建日期', 'date', 'created_date', 'datetime', 1, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0, 1, 0, 0, NULL, 'notCreated', 1, 0, 0, NULL, NULL, 0, 1),
(8, 1, '唯一名称', '唯一名称', 'text', 'key_name', 'varchar', 200, NULL, NULL, NULL, NULL, 1, 1, 1, 0, 1, 0, 0, 0, NULL, 'notCreated', 1, 0, 1, NULL, NULL, 0, 1),
(9, 1, '状态', '状态', 'select', 'state', 'int', 15, 7, NULL, NULL, NULL, 2, 1, 2, 0, 0, 0, 0, 0, NULL, 'notCreated', 1, 0, 0, NULL, NULL, 0, 1),
(9, 1, '状态', '状态', 'select', 'state', 'int', 15, 9, NULL, NULL, NULL, 2, 1, 2, 0, 0, 0, 0, 0, NULL, 'notCreated', 1, 0, 0, NULL, NULL, 0, 1),
(10, 1, '确认日期', '确认日期', 'text', 'fixed_date', 'varchar', 19, NULL, NULL, NULL, NULL, 3, 1, 3, 1, 0, 0, 0, 0, NULL, 'notCreated', 1, 0, 0, NULL, NULL, 0, 1),
(11, 1, '描述说明', '描述说明', 'textArea', 'description', 'varchar', 1000, NULL, NULL, NULL, NULL, 4, 1, 4, 1, 0, 0, 1, 0, NULL, 'notCreated', 1, 0, 0, NULL, NULL, 0, 1),
(12, 1, '编码', '编码', 'text', 'code', 'varchar', 50, NULL, NULL, NULL, NULL, 5, 1, 5, 0, 0, 0, 1, 0, NULL, 'notCreated', 1, 0, 0, NULL, NULL, 0, 1);
Expand Down
2 changes: 1 addition & 1 deletion cmdb-ui/src/api/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ req.interceptors.response.use(
Vue.prototype.$Notice.error({
title: 'Error',
desc: errorMes,
duration: 0
duration: 10
})
}
if (!res.headers['username']) {
Expand Down
2 changes: 1 addition & 1 deletion cmdb-ui/src/pages/admin/cmdb-model-management.vue
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@
<Select
clearable
v-model="item.form.referenceId"
:disabled="item.form.status === 'decommissioned'"
:disabled="item.form.status !== 'notCreated'"
filterable
>
<Option
Expand Down
9 changes: 5 additions & 4 deletions cmdb-ui/src/pages/components/cmdb-table/edit-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ export default {
r_guid: '',
p_guid: '',
state: '',
fixed_date: ''
fixed_date: '',
isNewAddedRow: true
}
columns.forEach(x => {
obj[x] = row[x]
Expand Down Expand Up @@ -242,9 +243,9 @@ export default {
</div>
)
} else if (column.component === 'Input') {
if (!d[column.inputKey]) {
d[column.inputKey] = column.defaultValue
}
// if (!d[column.inputKey]) {
// d[column.inputKey] = column.defaultValue
// }
const props = {
...column,
data: this.inputSearch[column.inputKey].options,
Expand Down
3 changes: 3 additions & 0 deletions cmdb-ui/src/pages/components/cmdb-table/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ export default {
immediate: true
}
},
beforeDestroy () {
this.$emit('getSelectedRows', [], false)
},
computed: {},
methods: {
pushNewAddedRowToSelections (data) {
Expand Down

0 comments on commit 307fd70

Please sign in to comment.