1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
/*******************************************************************************
* Copyright (c) 2004, 2007 Boeing.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Boeing - initial API and implementation
*******************************************************************************/
package org.eclipse.osee.framework.skynet.core.internal.accessors;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
import org.eclipse.osee.framework.core.enums.CoreTranslatorId;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.message.ArtifactTypeCacheUpdateResponse;
import org.eclipse.osee.framework.core.message.ArtifactTypeCacheUpdateResponse.ArtifactTypeRow;
import org.eclipse.osee.framework.core.model.Branch;
import org.eclipse.osee.framework.core.model.cache.AbstractOseeCache;
import org.eclipse.osee.framework.core.model.cache.IOseeCache;
import org.eclipse.osee.framework.core.model.type.ArtifactType;
import org.eclipse.osee.framework.core.model.type.ArtifactTypeFactory;
import org.eclipse.osee.framework.core.model.type.AttributeType;
import org.eclipse.osee.framework.jdk.core.type.CompositeKeyHashMap;
import org.eclipse.osee.framework.jdk.core.type.Pair;
import org.eclipse.osee.framework.jdk.core.type.Triplet;
/**
* @author Roberto E. Escobar
*/
public class ClientArtifactTypeAccessor extends AbstractClientDataAccessor<ArtifactType> {
private final AbstractOseeCache<AttributeType> attrCache;
private final AbstractOseeCache<Branch> branchCache;
private final ArtifactTypeFactory artifactTypeFactory;
public ClientArtifactTypeAccessor(ArtifactTypeFactory artifactTypeFactory, AbstractOseeCache<AttributeType> attrCache, AbstractOseeCache<Branch> branchCache) {
super();
this.artifactTypeFactory = artifactTypeFactory;
this.attrCache = attrCache;
this.branchCache = branchCache;
}
private ArtifactTypeFactory getFactory() {
return artifactTypeFactory;
}
@Override
public void load(IOseeCache<ArtifactType> cache) throws OseeCoreException {
attrCache.ensurePopulated();
branchCache.ensurePopulated();
super.load(cache);
}
@Override
protected Collection<ArtifactType> updateCache(IOseeCache<ArtifactType> cache) throws OseeCoreException {
List<ArtifactType> updatedItems = new ArrayList<ArtifactType>();
ArtifactTypeCacheUpdateResponse response =
requestUpdateMessage(cache, CoreTranslatorId.ARTIFACT_TYPE_CACHE_UPDATE_RESPONSE);
ArtifactTypeFactory factory = getFactory();
for (ArtifactTypeRow row : response.getArtTypeRows()) {
ArtifactType cached =
factory.createOrUpdate(cache, row.getId(), row.getStorageState(), row.getGuid(), row.isAbstract(),
row.getName());
updatedItems.add(cached);
}
for (Entry<Integer, Integer[]> entry : response.getBaseToSuperTypes().entrySet()) {
ArtifactType baseType = cache.getById(entry.getKey());
Set<ArtifactType> superTypes = new HashSet<ArtifactType>();
for (Integer superId : entry.getValue()) {
ArtifactType superType = cache.getById(superId);
if (superType != null) {
superTypes.add(superType);
}
}
baseType.setSuperTypes(superTypes);
}
CompositeKeyHashMap<ArtifactType, Branch, Collection<AttributeType>> attrs =
new CompositeKeyHashMap<ArtifactType, Branch, Collection<AttributeType>>();
for (Triplet<Integer, Integer, Integer> entry : response.getAttributeTypes()) {
ArtifactType key1 = cache.getById(entry.getFirst());
Branch key2 = branchCache.getById(entry.getSecond());
Collection<AttributeType> types = attrs.get(key1, key2);
if (types == null) {
types = new HashSet<AttributeType>();
attrs.put(key1, key2, types);
}
types.add(attrCache.getById(entry.getThird()));
}
for (Entry<Pair<ArtifactType, Branch>, Collection<AttributeType>> entry : attrs.entrySet()) {
entry.getKey().getFirst().setAttributeTypes(entry.getValue(), entry.getKey().getSecond());
}
return updatedItems;
}
}
|