TSK-623 BUG link children classification correctly to it parent
Link children classification to it corresponding parent in root domain when creating a new children classification in one specific domain.
This commit is contained in:
parent
a576ed98fb
commit
801e76498e
|
|
@ -37,6 +37,32 @@ public class ClassificationImpl implements Classification {
|
||||||
ClassificationImpl() {
|
ClassificationImpl() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ClassificationImpl(ClassificationImpl classification) {
|
||||||
|
this.id = classification.getId();
|
||||||
|
this.key = classification.getKey();
|
||||||
|
this.parentId = classification.getParentId();
|
||||||
|
this.parentKey = classification.getParentKey();
|
||||||
|
this.category = classification.getCategory();
|
||||||
|
this.type = classification.getType();
|
||||||
|
this.domain = classification.getDomain();
|
||||||
|
this.isValidInDomain = classification.getIsValidInDomain();
|
||||||
|
this.created = classification.getCreated();
|
||||||
|
this.modified = classification.getModified();
|
||||||
|
this.name = classification.getName();
|
||||||
|
this.description = classification.getDescription();
|
||||||
|
this.priority = classification.getPriority();
|
||||||
|
this.serviceLevel = classification.getServiceLevel();
|
||||||
|
this.applicationEntryPoint = classification.getApplicationEntryPoint();
|
||||||
|
this.custom1 = classification.getCustom1();
|
||||||
|
this.custom2 = classification.getCustom2();
|
||||||
|
this.custom3 = classification.getCustom3();
|
||||||
|
this.custom4 = classification.getCustom4();
|
||||||
|
this.custom5 = classification.getCustom5();
|
||||||
|
this.custom6 = classification.getCustom6();
|
||||||
|
this.custom7 = classification.getCustom7();
|
||||||
|
this.custom8 = classification.getCustom8();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return id;
|
return id;
|
||||||
|
|
|
||||||
|
|
@ -126,38 +126,50 @@ public class ClassificationServiceImpl implements ClassificationService {
|
||||||
private void addClassificationToRootDomain(ClassificationImpl classificationImpl) {
|
private void addClassificationToRootDomain(ClassificationImpl classificationImpl) {
|
||||||
if (!Objects.equals(classificationImpl.getDomain(), "")) {
|
if (!Objects.equals(classificationImpl.getDomain(), "")) {
|
||||||
boolean doesExist = true;
|
boolean doesExist = true;
|
||||||
String idBackup = classificationImpl.getId();
|
ClassificationImpl rootClassification = new ClassificationImpl(classificationImpl);
|
||||||
String domainBackup = classificationImpl.getDomain();
|
rootClassification.setId(IdGenerator.generateWithPrefix(ID_PREFIX_CLASSIFICATION));
|
||||||
boolean isValidInDomainBackup = classificationImpl.getIsValidInDomain();
|
rootClassification.setParentId(getClassificationRootDomainParentId(classificationImpl));
|
||||||
classificationImpl.setId(IdGenerator.generateWithPrefix(ID_PREFIX_CLASSIFICATION));
|
rootClassification.setDomain("");
|
||||||
classificationImpl.setDomain("");
|
rootClassification.setIsValidInDomain(false);
|
||||||
classificationImpl.setIsValidInDomain(false);
|
|
||||||
try {
|
try {
|
||||||
this.getClassification(classificationImpl.getKey(), classificationImpl.getDomain());
|
this.getClassification(rootClassification.getKey(), rootClassification.getDomain());
|
||||||
throw new ClassificationAlreadyExistException(classificationImpl);
|
throw new ClassificationAlreadyExistException(rootClassification);
|
||||||
} catch (ClassificationNotFoundException e) {
|
} catch (ClassificationNotFoundException e) {
|
||||||
doesExist = false;
|
doesExist = false;
|
||||||
LOGGER.debug(
|
LOGGER.debug(
|
||||||
"Method createClassification: Classification does not exist in root domain. Classification {}.",
|
"Method createClassification: Classification does not exist in root domain. Classification {}.",
|
||||||
classificationImpl);
|
rootClassification);
|
||||||
} catch (ClassificationAlreadyExistException ex) {
|
} catch (ClassificationAlreadyExistException ex) {
|
||||||
LOGGER.warn(
|
LOGGER.warn(
|
||||||
"Method createClassification: Classification does already exist in root domain. Classification {}.",
|
"Method createClassification: Classification does already exist in root domain. Classification {}.",
|
||||||
classificationImpl);
|
rootClassification);
|
||||||
} finally {
|
} finally {
|
||||||
if (!doesExist) {
|
if (!doesExist) {
|
||||||
classificationMapper.insert(classificationImpl);
|
classificationMapper.insert(rootClassification);
|
||||||
LOGGER.debug(
|
LOGGER.debug(
|
||||||
"Method createClassification: Classification created in root-domain, too. Classification {}.",
|
"Method createClassification: Classification created in root-domain, too. Classification {}.",
|
||||||
classificationImpl);
|
rootClassification);
|
||||||
}
|
}
|
||||||
classificationImpl.setId(idBackup);
|
|
||||||
classificationImpl.setDomain(domainBackup);
|
|
||||||
classificationImpl.setIsValidInDomain(isValidInDomainBackup);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getClassificationRootDomainParentId(ClassificationImpl classificationImpl) {
|
||||||
|
String rootParentId = "";
|
||||||
|
try {
|
||||||
|
if (classificationImpl.getParentId() != null && !"".equals(classificationImpl.getParentId())) {
|
||||||
|
rootParentId = this.getClassification(this.getClassification(classificationImpl.getParentId()).getKey(),
|
||||||
|
"")
|
||||||
|
.getId();
|
||||||
|
}
|
||||||
|
} catch (ClassificationNotFoundException e) {
|
||||||
|
LOGGER.warn(
|
||||||
|
"Method getRootDomainParentIdClassification: Cannot find parent classification in Root domain. Classification {}.",
|
||||||
|
classificationImpl);
|
||||||
|
}
|
||||||
|
return rootParentId;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Classification updateClassification(Classification classification)
|
public Classification updateClassification(Classification classification)
|
||||||
throws NotAuthorizedException, ConcurrencyException, ClassificationNotFoundException, InvalidArgumentException {
|
throws NotAuthorizedException, ConcurrencyException, ClassificationNotFoundException, InvalidArgumentException {
|
||||||
|
|
|
||||||
|
|
@ -201,6 +201,28 @@ public class ClassificationServiceImplTest {
|
||||||
assertThat(classification.getKey(), equalTo(key));
|
assertThat(classification.getKey(), equalTo(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateChildClassificationInOwnDomainAndCopyInRootDomain()
|
||||||
|
throws ClassificationAlreadyExistException, NotAuthorizedException, DomainNotFoundException,
|
||||||
|
InvalidArgumentException {
|
||||||
|
Classification classification = createDummyClassification("");
|
||||||
|
classification.setParentId("parentId");
|
||||||
|
ClassificationImpl parentRootClassification = (ClassificationImpl) createDummyClassification("ParentIdRoot");
|
||||||
|
parentRootClassification.setKey("ParentKey");
|
||||||
|
parentRootClassification.setDomain("");
|
||||||
|
doReturn(null).when(classificationMapperMock).findByKeyAndDomain(classification.getKey(),
|
||||||
|
classification.getDomain());
|
||||||
|
doReturn(null).when(classificationMapperMock).findByKeyAndDomain(classification.getKey(), "");
|
||||||
|
doReturn(parentRootClassification).when(classificationMapperMock).findByKeyAndDomain("ParentKey", "");
|
||||||
|
|
||||||
|
doReturn(parentRootClassification).when(classificationMapperMock).findById("parentId");
|
||||||
|
doReturn(true).when(taskanaEngineImplMock).domainExists(any());
|
||||||
|
|
||||||
|
cutSpy.createClassification(classification);
|
||||||
|
|
||||||
|
verify(classificationMapperMock, times(1)).findByKeyAndDomain("ParentKey", "");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateClassificationIntoRootDomain()
|
public void testCreateClassificationIntoRootDomain()
|
||||||
throws ClassificationAlreadyExistException, NotAuthorizedException,
|
throws ClassificationAlreadyExistException, NotAuthorizedException,
|
||||||
|
|
|
||||||
|
|
@ -217,6 +217,42 @@ public class ClassificationControllerIntTest {
|
||||||
con.disconnect();
|
con.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateClassificationWithParentKeyInDOMAIN_AShouldCreateAClassificationInRootDomain()
|
||||||
|
throws IOException {
|
||||||
|
String newClassification = "{\"classificationId\":\"\",\"category\":\"MANUAL\",\"domain\":\"DOMAIN_A\",\"key\":\"NEW_CLASS_P2\",\"name\":\"new classification\",\"type\":\"TASK\",\"parentKey\":\"T2100\"}";
|
||||||
|
|
||||||
|
URL url = new URL(server + port + "/v1/classifications");
|
||||||
|
HttpURLConnection con = (HttpURLConnection) url.openConnection();
|
||||||
|
con.setRequestMethod("POST");
|
||||||
|
con.setRequestProperty("Authorization", "Basic dGVhbWxlYWRfMTp0ZWFtbGVhZF8x");
|
||||||
|
con.setDoOutput(true);
|
||||||
|
con.setRequestProperty("Content-Type", "application/json");
|
||||||
|
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(con.getOutputStream()));
|
||||||
|
out.write(newClassification);
|
||||||
|
out.flush();
|
||||||
|
out.close();
|
||||||
|
assertEquals(201, con.getResponseCode());
|
||||||
|
con.disconnect();
|
||||||
|
|
||||||
|
ResponseEntity<PagedResources<ClassificationSummaryResource>> response = template.exchange(
|
||||||
|
server + port + "/v1/classifications", HttpMethod.GET,
|
||||||
|
request,
|
||||||
|
new ParameterizedTypeReference<PagedResources<ClassificationSummaryResource>>() {
|
||||||
|
|
||||||
|
});
|
||||||
|
assertNotNull(response.getBody().getLink(Link.REL_SELF));
|
||||||
|
boolean foundClassificationCreated = false;
|
||||||
|
for (ClassificationSummaryResource classification : response.getBody().getContent()) {
|
||||||
|
if ("NEW_CLASS_P2".equals(classification.getKey()) && "".equals(classification.getDomain())
|
||||||
|
&& "T2100".equals(classification.getParentKey())) {
|
||||||
|
foundClassificationCreated = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals(true, foundClassificationCreated);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReturn400IfCreateClassificationWithIncompatibleParentIdAndKey() throws IOException {
|
public void testReturn400IfCreateClassificationWithIncompatibleParentIdAndKey() throws IOException {
|
||||||
String newClassification = "{\"classificationId\":\"\",\"category\":\"MANUAL\",\"domain\":\"DOMAIN_B\",\"key\":\"NEW_CLASS_P3\",\"name\":\"new classification\",\"type\":\"TASK\",\"parentId\":\"CLI:200000000000000000000000000000000015\",\"parentKey\":\"T2000\"}";
|
String newClassification = "{\"classificationId\":\"\",\"category\":\"MANUAL\",\"domain\":\"DOMAIN_B\",\"key\":\"NEW_CLASS_P3\",\"name\":\"new classification\",\"type\":\"TASK\",\"parentId\":\"CLI:200000000000000000000000000000000015\",\"parentKey\":\"T2000\"}";
|
||||||
|
|
@ -433,7 +469,7 @@ public class ClassificationControllerIntTest {
|
||||||
converter.setSupportedMediaTypes(MediaType.parseMediaTypes("application/hal+json"));
|
converter.setSupportedMediaTypes(MediaType.parseMediaTypes("application/hal+json"));
|
||||||
converter.setObjectMapper(mapper);
|
converter.setObjectMapper(mapper);
|
||||||
|
|
||||||
RestTemplate template = new RestTemplate(Collections.<HttpMessageConverter<?>> singletonList(converter));
|
RestTemplate template = new RestTemplate(Collections.<HttpMessageConverter<?>>singletonList(converter));
|
||||||
return template;
|
return template;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Component, OnInit, Input, Output, EventEmitter, ViewChild, AfterViewChecked, OnChanges, SimpleChanges } from '@angular/core';
|
import { Component, OnInit, Input, Output, EventEmitter, ViewChild, AfterViewChecked, OnDestroy } from '@angular/core';
|
||||||
import { TreeNodeModel } from 'app/models/tree-node';
|
import { TreeNodeModel } from 'app/models/tree-node';
|
||||||
|
|
||||||
import { KEYS, ITreeOptions, TreeComponent, TreeNode } from 'angular-tree-component';
|
import { KEYS, ITreeOptions, TreeComponent, TreeNode } from 'angular-tree-component';
|
||||||
|
|
@ -7,13 +7,14 @@ import {
|
||||||
ClassificationCategoriesService
|
ClassificationCategoriesService
|
||||||
} from 'app/administration/services/classification-categories-service/classification-categories.service';
|
} from 'app/administration/services/classification-categories-service/classification-categories.service';
|
||||||
import { Pair } from 'app/models/pair';
|
import { Pair } from 'app/models/pair';
|
||||||
|
import { Subscription } from 'rxjs/Subscription';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'taskana-tree',
|
selector: 'taskana-tree',
|
||||||
templateUrl: './tree.component.html',
|
templateUrl: './tree.component.html',
|
||||||
styleUrls: ['./tree.component.scss']
|
styleUrls: ['./tree.component.scss']
|
||||||
})
|
})
|
||||||
export class TaskanaTreeComponent implements OnInit, AfterViewChecked {
|
export class TaskanaTreeComponent implements OnInit, AfterViewChecked, OnDestroy {
|
||||||
|
|
||||||
|
|
||||||
@ViewChild('tree')
|
@ViewChild('tree')
|
||||||
|
|
@ -29,6 +30,7 @@ export class TaskanaTreeComponent implements OnInit, AfterViewChecked {
|
||||||
|
|
||||||
private filterTextOld: string
|
private filterTextOld: string
|
||||||
private filterIconOld: string
|
private filterIconOld: string
|
||||||
|
private removedNodeIdSubscription: Subscription;
|
||||||
|
|
||||||
options: ITreeOptions = {
|
options: ITreeOptions = {
|
||||||
displayField: 'name',
|
displayField: 'name',
|
||||||
|
|
@ -48,7 +50,7 @@ export class TaskanaTreeComponent implements OnInit, AfterViewChecked {
|
||||||
constructor(private treeService: TreeService, private categoryService: ClassificationCategoriesService) { }
|
constructor(private treeService: TreeService, private categoryService: ClassificationCategoriesService) { }
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.treeService.getRemovedNodeId().subscribe(value => {
|
this.removedNodeIdSubscription = this.treeService.getRemovedNodeId().subscribe(value => {
|
||||||
const removedNode = this.getNode(value);
|
const removedNode = this.getNode(value);
|
||||||
if (removedNode.parent) {
|
if (removedNode.parent) {
|
||||||
removedNode.parent.collapse();
|
removedNode.parent.collapse();
|
||||||
|
|
@ -135,5 +137,10 @@ export class TaskanaTreeComponent implements OnInit, AfterViewChecked {
|
||||||
this.tree.treeModel.collapseAll();
|
this.tree.treeModel.collapseAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngOnDestroy(): void {
|
||||||
|
if (this.removedNodeIdSubscription) { this.removedNodeIdSubscription.unsubscribe() }
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue