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
|
/*******************************************************************************
* 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.List;
import org.eclipse.osee.framework.core.data.IArtifactType;
import org.eclipse.osee.framework.core.enums.CoreTranslatorId;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.message.RelationTypeCacheUpdateResponse;
import org.eclipse.osee.framework.core.message.RelationTypeCacheUpdateResponse.RelationTypeRow;
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.RelationType;
import org.eclipse.osee.framework.core.model.type.RelationTypeFactory;
/**
* @author Roberto E. Escobar
*/
public class ClientRelationTypeAccessor extends AbstractClientDataAccessor<String, RelationType> {
private final AbstractOseeCache<String, ArtifactType> artCache;
private final RelationTypeFactory relationTypeFactory;
public ClientRelationTypeAccessor(RelationTypeFactory relationTypeFactory, AbstractOseeCache<String, ArtifactType> artCache) {
super();
this.relationTypeFactory = relationTypeFactory;
this.artCache = artCache;
}
private RelationTypeFactory getFactory() {
return relationTypeFactory;
}
@Override
public void load(IOseeCache<String, RelationType> cache) throws OseeCoreException {
artCache.ensurePopulated();
super.load(cache);
}
@Override
protected Collection<RelationType> updateCache(IOseeCache<String, RelationType> cache) throws OseeCoreException {
List<RelationType> updatedItems = new ArrayList<RelationType>();
RelationTypeCacheUpdateResponse response =
requestUpdateMessage(cache, CoreTranslatorId.RELATION_TYPE_CACHE_UPDATE_RESPONSE);
RelationTypeFactory factory = getFactory();
for (RelationTypeRow row : response.getRelationTypeRows()) {
IArtifactType aSideType = artCache.getById(row.getArtifactTypeSideA());
IArtifactType bSideType = artCache.getById(row.getArtifactTypeSideB());
RelationType type =
factory.createOrUpdate(cache, row.getId(), row.getStorageState(), row.getGuid(), row.getName(),
row.getSideAName(), row.getSideBName(), aSideType, bSideType, row.getMultiplicity(),
row.getDefaultOrderTypeGuid());
updatedItems.add(type);
}
return updatedItems;
}
}
|