-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'remotes/origin/custom_async_init'
- Loading branch information
Showing
6 changed files
with
148 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/main/java/com/hpe/adm/octane/ideplugins/services/MetadataService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.hpe.adm.octane.ideplugins.services; | ||
|
||
import com.google.inject.Inject; | ||
import com.hpe.adm.nga.sdk.Octane; | ||
import com.hpe.adm.nga.sdk.metadata.FieldMetadata; | ||
import com.hpe.adm.octane.ideplugins.services.connection.ConnectionSettingsProvider; | ||
import com.hpe.adm.octane.ideplugins.services.connection.OctaneProvider; | ||
import com.hpe.adm.octane.ideplugins.services.filtering.Entity; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.stream.Collectors; | ||
|
||
public class MetadataService { | ||
|
||
@Inject | ||
private OctaneProvider octaneProvider; | ||
|
||
@Inject | ||
private ConnectionSettingsProvider connectionSettingsProvider; | ||
|
||
private Map<Entity, Collection<FieldMetadata>> cache; | ||
|
||
public boolean hasFields(Entity entityType, String... fieldNames){ | ||
|
||
if(cache == null){ | ||
cache = new ConcurrentHashMap<>(); | ||
init(); | ||
} | ||
|
||
Octane octane = octaneProvider.getOctane(); | ||
|
||
Collection<FieldMetadata> fields; | ||
|
||
if(!cache.containsKey(entityType)){ | ||
fields = octane.metadata().fields(entityType.getEntityName()).execute(); | ||
cache.put(entityType, fields); | ||
} else { | ||
fields = cache.get(entityType); | ||
} | ||
|
||
List<String> responseFieldNames = fields.stream().map(FieldMetadata::getName).collect(Collectors.toList()); | ||
|
||
return Arrays.stream(fieldNames) | ||
.allMatch(responseFieldNames::contains); | ||
} | ||
|
||
public void eagerInit(Entity... entities){ | ||
if(cache == null){ | ||
cache = new ConcurrentHashMap<>(); | ||
init(); | ||
} | ||
|
||
Octane octane = octaneProvider.getOctane(); | ||
|
||
Arrays.stream(entities) | ||
.parallel() | ||
.forEach(entityType -> cache.put(entityType, octane.metadata().fields(entityType.getEntityName()).execute())); | ||
} | ||
|
||
private void init(){ | ||
cache = new ConcurrentHashMap<>(); | ||
connectionSettingsProvider.addChangeHandler(()-> cache.clear()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters