Rena Tsantouli 2009-04-10 14:30:24 +00:00
parent bb85bb6e9b
commit 4660327219
10 changed files with 68 additions and 1198 deletions

View File

@ -1,16 +1,12 @@
package org.gcube.application.framework.core.cache;
import org.gcube.application.framework.core.cache.factories.CollectionCacheEntryFactory;
import org.gcube.application.framework.core.cache.factories.ContentInfoCacheEntryFactory;
import java.util.HashMap;
import org.gcube.application.framework.core.cache.factories.GenericResourceCacheEntryFactory;
import org.gcube.application.framework.core.cache.factories.MetadataCacheEntryFactory;
import org.gcube.application.framework.core.cache.factories.ProfileCacheEntryFactory;
import org.gcube.application.framework.core.cache.factories.SchemaInfoCacheEntryFactory;
import org.gcube.application.framework.core.cache.factories.SearchConfigCacheEntryFactory;
import org.gcube.application.framework.core.cache.factories.ThumbnailCacheEntryFactory;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Ehcache;
import net.sf.ehcache.constructs.blocking.CacheEntryFactory;
import net.sf.ehcache.constructs.blocking.SelfPopulatingCache;
/**
@ -22,14 +18,16 @@ import net.sf.ehcache.constructs.blocking.SelfPopulatingCache;
public class CachesManager {
protected static CachesManager cacheManager = new CachesManager();
protected CacheManager manager;
protected Ehcache profileCache;
protected Ehcache genericResourceCache;
protected Ehcache searchConfigCache;
protected Ehcache collectionCache;
protected Ehcache contentCache;
protected Ehcache thumbnailCache;
protected Ehcache schemataCache;
protected Ehcache metadataCache;
// protected Ehcache profileCache;
// protected Ehcache genericResourceCache;
// protected Ehcache searchConfigCache;
// protected Ehcache collectionCache;
// protected Ehcache contentCache;
// protected Ehcache thumbnailCache;
// protected Ehcache schemataCache;
// protected Ehcache metadataCache;
protected HashMap<String, Ehcache> caches;
/**
* The constructor
@ -38,23 +36,26 @@ public class CachesManager {
manager = CacheManager.create(CachesManager.class.getResource("/etc/ehcache.xml"));
profileCache = manager.getEhcache("profiles");
genericResourceCache = manager.getEhcache("genericResources");
searchConfigCache = manager.getEhcache("searchConfiguration");
collectionCache = manager.getEhcache("collections");
contentCache = manager.getEhcache("content");
thumbnailCache = manager.getEhcache("thumbnail");
schemataCache = manager.getEhcache("schemata");
metadataCache = manager.getEhcache("metadata");
caches = new HashMap<String, Ehcache>();
profileCache = new SelfPopulatingCache(profileCache, new ProfileCacheEntryFactory());
// profileCache = manager.getEhcache("profiles");
Ehcache genericResourceCache = manager.getEhcache("genericResources");
// searchConfigCache = manager.getEhcache("searchConfiguration");
// collectionCache = manager.getEhcache("collections");
// contentCache = manager.getEhcache("content");
// thumbnailCache = manager.getEhcache("thumbnail");
// schemataCache = manager.getEhcache("schemata");
// metadataCache = manager.getEhcache("metadata");
// profileCache = new SelfPopulatingCache(profileCache, new ProfileCacheEntryFactory());
genericResourceCache = new SelfPopulatingCache(genericResourceCache, new GenericResourceCacheEntryFactory());
searchConfigCache = new SelfPopulatingCache(searchConfigCache, new SearchConfigCacheEntryFactory());
collectionCache = new SelfPopulatingCache(collectionCache, new CollectionCacheEntryFactory());
contentCache = new SelfPopulatingCache(contentCache, new ContentInfoCacheEntryFactory());
thumbnailCache = new SelfPopulatingCache(thumbnailCache, new ThumbnailCacheEntryFactory());
schemataCache = new SelfPopulatingCache(schemataCache, new SchemaInfoCacheEntryFactory());
metadataCache = new SelfPopulatingCache(metadataCache, new MetadataCacheEntryFactory());
caches.put("genericResourceCache", genericResourceCache);
// searchConfigCache = new SelfPopulatingCache(searchConfigCache, new SearchConfigCacheEntryFactory());
// collectionCache = new SelfPopulatingCache(collectionCache, new CollectionCacheEntryFactory());
// contentCache = new SelfPopulatingCache(contentCache, new ContentInfoCacheEntryFactory());
// thumbnailCache = new SelfPopulatingCache(thumbnailCache, new ThumbnailCacheEntryFactory());
// schemataCache = new SelfPopulatingCache(schemataCache, new SchemaInfoCacheEntryFactory());
// metadataCache = new SelfPopulatingCache(metadataCache, new MetadataCacheEntryFactory());
}
/**
@ -63,61 +64,74 @@ public class CachesManager {
public static CachesManager getInstance() {
return cacheManager;
}
public Ehcache getEhcache (String cacheName, CacheEntryFactory cacheFactory) {
if (caches.get(cacheName) == null) {
Ehcache newCache = manager.getEhcache(cacheName);
newCache = new SelfPopulatingCache(newCache, cacheFactory);
caches.put(cacheName, newCache);
}
return caches.get(cacheName);
}
/**
* @return the cache that contains the user profiles
*/
public Ehcache getProfileCache() {
return profileCache;
}
// public Ehcache getProfileCache() {
// return profileCache;
// }
/**
* @return the cache that contains the generic resources
*/
public Ehcache getGenericResourceCache() {
return genericResourceCache;
return caches.get("genericResourceCache");
}
/**
* @return the cache that contains the search configurations
*/
public Ehcache getSearchConfigCache() {
return searchConfigCache;
}
// public Ehcache getSearchConfigCache() {
// return searchConfigCache;
// }
/**
* @return the cache that contains the collections per VRE
*/
public Ehcache getCollectionCache() {
return collectionCache;
}
// public Ehcache getCollectionCache() {
// return collectionCache;
// }
/**
* @return the cache that contains information about digital objects
*/
public Ehcache getContentCache() {
return contentCache;
}
// public Ehcache getContentCache() {
// return contentCache;
// }
/**
* @return the cache that contains thumbnails
*/
public Ehcache getThumbnailCache() {
return thumbnailCache;
}
// public Ehcache getThumbnailCache() {
// return thumbnailCache;
// }
/**
* @return the cache that contains the searchable fields for each metadata schema
*/
public Ehcache getSchemataCache() {
return schemataCache;
}
// public Ehcache getSchemataCache() {
// return schemataCache;
// }
/**
* @return the cache that contains the metadata objects
*/
public Ehcache getMetadataCache() {
return metadataCache;
}
// public Ehcache getMetadataCache() {
// return metadataCache;
// }
}

View File

@ -16,7 +16,7 @@ import org.gridforum.jgss.ExtendedGSSCredential;
* @author Valia Tsagkalidou (NKUA)
*
*/
class ApplicationCredentials {
public class ApplicationCredentials {
private static ApplicationCredentials applCredentials = new ApplicationCredentials();
private HashMap<String, ExtendedGSSCredential> creds;
protected static String userDN = "/O=Grid/OU=GlobusTest/OU=simpleCA-gauss.eng.it/OU=eng.it/CN=";

View File

@ -1,401 +0,0 @@
package org.gcube.application.framework.core.cache.factories;
import org.apache.axis.message.addressing.EndpointReferenceType;
import org.xml.sax.InputSource;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.ArrayList;
import java.io.StringReader;
import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.xpath.XPathAPI;
import org.gcube.application.framework.core.cache.CachesManager;
import org.gcube.application.framework.core.commons.model.CollectionInfo;
import org.gcube.application.framework.core.commons.model.IndexInfo;
import org.gcube.application.framework.core.util.CacheEntryConstants;
import org.gcube.application.framework.core.util.QueryString;
import org.gcube.application.framework.core.util.SessionConstants;
import org.gcube.application.framework.core.vremanagement.model.ISGenericResource;
import org.gcube.common.core.contexts.GHNContext;
import org.gcube.common.core.informationsystem.client.ISClient;
import org.gcube.common.core.informationsystem.client.RPDocument;
import org.gcube.common.core.informationsystem.client.queries.WSResourceQuery;
import org.gcube.common.core.scope.GCUBEScope;
import org.gcube.common.core.utils.logging.GCUBELog;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import net.sf.ehcache.constructs.blocking.CacheEntryFactory;
/**
* This cache serves the available searchable collections for each VRE
* @author Valia Tsagkalidou (NKUA)
*
*/
public class CollectionCacheEntryFactory implements CacheEntryFactory {
static ISClient client = null;
/** Object logger. */
protected final GCUBELog logger = new GCUBELog(this);
public CollectionCacheEntryFactory() {
super();
//Initialize static variable
if(client == null)
{
try {
client = GHNContext.getImplementation(ISClient.class);
} catch (Exception e) {
// TODO Auto-generated catch block
logger.error("Failed to get implemetation of ISClient", e);
}
}
}
/**
* Document factory instance
*/
public static final DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
/**
* whether geospatial tab should be available in Search portlet or not
*/
protected boolean geospatial;
//TODO: find a way to return also the geospatial tab boolean variable
/**
* @param key a String representing the VRE name.
* @return List<CollectionInfo>[] an array of Lists containing CollectionInfo objects. Each List contains a Collection group. The First element of the list is the CollectionInfo containing info for the Group (name, description etc). The rest of the objects in the list are the actual collections.
*/
public Object createEntry(Object key) throws Exception {
System.out.println("GenericResource: inside collection cache entry factory create entry");
List<CollectionInfo> collections;
String searchConfig = (String) CachesManager.getInstance().getSearchConfigCache().get(key).getValue();
System.out.println("The search configuration returned from the search master (dynamic) is: " + searchConfig);
if(searchConfig == null || searchConfig.equals("")) {
System.out.println("The searchConfigCache returned null for the search configuration!!!!");
return null;
}
collections = parseSearchConfig(searchConfig);
System.out.println("GenericResource - Inside collection cache entry factory calling retrieve static configuration");
return retrieveStaticConfiguration(key.toString(), collections);
}
/**
* @param searchConfig the search configuration as it is returned from the SearchMaster
* @return a list of CollectionInfo, which represents the currently available collections
*/
protected List<CollectionInfo> parseSearchConfig(String searchConfig)
{
try {
// Interpreting the dynamic configuration (the one retrieved from Search Master)
logger.debug(searchConfig);
InputSource colls_in = new InputSource(new StringReader(searchConfig));
Document colls_doc;
colls_doc = dfactory.newDocumentBuilder().parse(colls_in);
NodeList colls_res;
//Getting the info of all the available content collections:
colls_res = XPathAPI.selectNodeList(colls_doc, "/SearchConfig/collections/collection[TYPE='DATA']");
int n = colls_res.getLength(),i;
List<CollectionInfo> collections = new ArrayList<CollectionInfo>();
for (i = 0; i < n; i++)
{//For each content collection:
// Storing the information in local variables.
CollectionInfo colInfo = new CollectionInfo();
String val;
String id = colls_res.item(i).getAttributes().getNamedItem("id").getNodeValue();
val = id;
String colName = colls_res.item(i).getAttributes().getNamedItem("name").getNodeValue();
colInfo.setId(id);
colInfo.setName(colName);
NodeList contentRes = XPathAPI.selectNodeList(colls_doc, "/SearchConfig/collections/collection[@id='"+id+"']/ASSOCIATEDWITH");
int attrNo = contentRes.getLength();
for(int j=0; j<attrNo; j++)
{//For each corresponding metadata collection:
try
{
String metadataID = contentRes.item(j).getFirstChild().getNodeValue();
String language = null, schema = null;
// get the language of this collection:
NodeList metaRes = XPathAPI.selectNodeList(colls_doc, "/SearchConfig/collections/collection[@id='"+metadataID+"']/"+"LANGUAGE");
if(metaRes == null)
continue;
language = metaRes.item(0).getFirstChild().getNodeValue();
// get the schema of this collection:
metaRes = XPathAPI.selectNodeList(colls_doc, "/SearchConfig/collections/collection[@id='"+metadataID+"']/"+"SCHEMA");
if(metaRes != null)
schema = metaRes.item(0).getFirstChild().getNodeValue();
// get the available indices for this collection:
metaRes = XPathAPI.selectNodeList(colls_doc, "/SearchConfig/collections/collection[@id='"+metadataID+"']/"+"INDEX");
IndexInfo indexInformation = new IndexInfo();
if(metaRes != null)
{
logger.debug("collection: " + colInfo.getName() + " schema = " + metaRes);
int k, total = metaRes.getLength();
for(k=0; k<total; k++)
{//For each Index:
logger.debug(" -- " + metaRes.item(k).getFirstChild().getNodeValue());
if(metaRes.item(k).getFirstChild().getNodeValue().equals("FTS"))
{
indexInformation.setFts(true);
logger.debug("id name : "+val);
}
else if(metaRes.item(k).getFirstChild().getNodeValue().equals("GEO"))
{
indexInformation.setGeospatial(true);
logger.debug("id name : "+val);
}
else if(metaRes.item(k).getFirstChild().getNodeValue().equals("FEATURE"))
{
//This is probably deprecated. It refers to feature indices which are no longer available on the infrastructure.
indexInformation.setSimilarity(true);
logger.debug("id name : "+val);
}
}
}
colInfo.setMetadataCollection(schema, metadataID, language, indexInformation);
}
catch (Exception e) {
logger.error("", e);
}
}//End of for each metadata collection.
collections.add(colInfo);
}//End of for each content collection.
return collections;
} catch (Exception e1) {
logger.error("", e1);
}
return null;
}
/**
* Retrieves the static configuration for the collections from the IS. This information is stored in a generic resource published on IS.
* @param vre the vre for which it will retrieve the static configuration (generic resource in IS)
* @param collections the collection derived from the dynamic configuration (SearchMaster configuration)
* @return an array of Lists containing CollectionInfo objects. Each List contains a Collection group. The First element of the list is the CollectionInfo containing info for the Group (name, description etc). The rest of the objects in the list are the actual collections.
* @throws Exception an Exception occurred during the procedure
*/
protected List<CollectionInfo>[] retrieveStaticConfiguration(String vre, List<CollectionInfo> collections) throws Exception
{
// Reading the static configuration file and initializing the parameters
System.out.println("About to retrieve the static configuration");
List<CollectionInfo>[] colHierarchy;
QueryString query = new QueryString();
query.put(CacheEntryConstants.vre, vre);
query.put(CacheEntryConstants.name, SessionConstants.ScenarioSchemaInfo);
//Retrieving the generic resource:
List<ISGenericResource> scenarioSchemaInfo = (List<ISGenericResource>) CachesManager.getInstance().getGenericResourceCache().get(query).getValue();
if(scenarioSchemaInfo == null || scenarioSchemaInfo.size() == 0)
{
System.out.println("The scenarioSchemaInfo is null");
colHierarchy = new ArrayList[0];
return colHierarchy;
}
System.out.println("Printing the static configuration");
logger.debug(scenarioSchemaInfo.get(0).getBody());
InputSource in = new InputSource(new StringReader(scenarioSchemaInfo.get(0).getBody()));
Document doc = dfactory.newDocumentBuilder().parse(in);
retrieveCollections(doc, collections);
colHierarchy = retrieveCollectionHierarchy(vre, doc, collections);
return colHierarchy;
}
/**
* Retrieves the collections by joining information from static and dynamic configuration.
* @param doc document which holds the collections
* @param collections the list containing the collections
*/
protected void retrieveCollections(Document doc, List<CollectionInfo> collections)
{
int i,n;
List<CollectionInfo> availableCollections = new ArrayList<CollectionInfo>();
// Reading the collections and storing them in a list only if they are currently available.
NodeList res = doc.getElementsByTagName("collection");
n = res.getLength();
System.out.println("CollectionCacheEntryFactory: The number of collections is: " + n);
for (i = 0; i < n; i++)
{
String val = res.item(i).getAttributes().getNamedItem("name").getNodeValue();
CollectionInfo colInfo = null;
colInfo = getCollectionInfo(val, collections);
if (colInfo == null)
continue;// This collection is not currently available.
val = res.item(i).getAttributes().getNamedItem("description").getNodeValue();
colInfo.setDescription(val);
val = res.item(i).getAttributes().getNamedItem("reference").getNodeValue();
colInfo.setReference(val);
val = res.item(i).getAttributes().getNamedItem("shortname").getNodeValue();
colInfo.setShortName(val);
availableCollections.add(colInfo);
}
//Copying available collections to collections
collections.clear();
for(CollectionInfo col : availableCollections)
{
collections.add(col);
}
//Adding the collection groups to the available collections
res = doc.getElementsByTagName("collections");
n = res.getLength();
for (i = 0; i < n; i++)
{
CollectionInfo colInfo = new CollectionInfo();
colInfo.setId("collection_id_"+i);
String val;
try{
val = res.item(i).getAttributes().getNamedItem("name").getNodeValue();
colInfo.setName(val);
}
catch(Exception e){}
try{
val = res.item(i).getAttributes().getNamedItem("description").getNodeValue();
colInfo.setDescription(val);
}
catch(Exception e){}
try{
val = res.item(i).getAttributes().getNamedItem("reference").getNodeValue();
colInfo.setReference(val);
}
catch(Exception e){}
try{
val = res.item(i).getAttributes().getNamedItem("shortname").getNodeValue();
colInfo.setShortName(val);
}
catch(Exception e){}
collections.add(colInfo);
}
logger.debug("***Number of collections:" + collections.size());
}
/**
* Retrieves the hierarchical structure of the available collections. Joins the static and the dynamic search configuration and produces a hierarchical structure containing information about each collection.
* @param VREname the VRE name of the active VRE
* @param doc document which holds the collections
* @param collections the available collections
* @return an array of Lists containing CollectionInfo objects. Each List contains a Collection group. The First element of the list is the CollectionInfo containing info for the Group (name, description etc). The rest of the objects in the list are the actual collections.
* @throws Exception an Exception occurred during processing
*/
protected List<CollectionInfo>[] retrieveCollectionHierarchy(String VREname, Document doc, List<CollectionInfo> collections) throws Exception {
// Retrieving the tree structure of the collection hierarchy
NodeList res = XPathAPI.selectNodeList(doc, "//DL");
Node geo = res.item(0).getAttributes().getNamedItem("geospatial");
if(geo != null && geo.getNodeValue().equals("true"))
geospatial = true;
res = XPathAPI.selectNodeList(doc, "//collections");
int n = res.getLength();
logger.debug("***** number of collection groups:" + n + "*******");
List<CollectionInfo>[] colHierachy = new List[n];
for (int i = 0; i < n; i++)
{//for each collection group:
String val = res.item(i).getAttributes().getNamedItem("name").getNodeValue();
NodeList res2 = XPathAPI.selectNodeList(doc, "//collections[@name=\"" + val + "\"]/collection");
colHierachy[i] = new ArrayList<CollectionInfo>();
CollectionInfo colInfo = getCollectionInfo(val, collections);
if(colInfo != null)
{
colHierachy[i].add(colInfo); // Collection Group Name
for (int j = 0; j < res2.getLength(); j++)
{//for each collection belonging to that group, it stores its name...
colInfo = getCollectionInfo(res2.item(j).getAttributes().getNamedItem("name").getNodeValue(), collections);
if(colInfo != null)
{
findBrowseFields(colInfo, GCUBEScope.getScope(VREname));
colHierachy[i].add(colInfo);
}
}
}
logger.debug("***collection group " + i + " contains " + (colHierachy[i].size()-1) + " collections***");
}
return colHierachy;
}
/**
* Finds the Browseable fields for the given collection
* @param colInfo the CollectionInfo containing info about the current collection
* @param scope the GCUBEScope of the active VRE
*/
private void findBrowseFields(CollectionInfo colInfo, GCUBEScope scope) {
try {
getWSResourceForForward(colInfo, scope);
} catch(Exception e){
e.printStackTrace();
}
}
/**
* Finds the collection info object of the collection with the given name.
* @param collectionName the name of the collection
* @param collections a list containing all the collections
* @return the CollectionInfo of the collection with the corresponding name
*/
protected CollectionInfo getCollectionInfo(String collectionName, List<CollectionInfo> collections)
{
CollectionInfo colInfo = null;
int i, n = collections.size();
for(i=0; i< n; i++)
{
logger.debug("*******" + collections.get(i).getName() + " vs. " + collectionName);
if(collections.get(i).getName().equals(collectionName))
{
colInfo = collections.get(i);
logger.debug("***collection found****");
break;
}
}
return colInfo;
}
/**
* Updates the information regarding the available forward indices for the given content collection
* @param colInfo the CollectionInfo that represents the content collection
* @param scope the scope on which this collection belongs to (currently active VRE)
* @throws Exception an error occurred during execution
*/
private void getWSResourceForForward(CollectionInfo colInfo, GCUBEScope scope) throws Exception {
//Building the query to IS
String filter = "$result/child::*[local-name()='ServiceClass']/string() eq 'Index'";
filter += " and $result/child::*[local-name()='ServiceName']/string() eq 'ForwardIndexLookup'";
filter += " and $result/child::*[local-name()='CollectionID']/string() eq '" + colInfo.getId() + "'";
HashMap<String, List<EndpointReferenceType>> results = colInfo.getForward();
ISClient client = GHNContext.getImplementation(ISClient.class);
WSResourceQuery gquery = client.getQuery(WSResourceQuery.class);
gquery.addGenericCondition(filter);
//For each result:
for(RPDocument d : client.execute(gquery, scope)){
String browseField = d.evaluate("//KeyName/text()").get(0);
List<EndpointReferenceType> ret = results.get(browseField);
if(ret == null)
{
ret = new LinkedList<EndpointReferenceType>();
}
ret.add(d.getEndpoint());
results.put(browseField, ret);
}
}
}

View File

@ -1,82 +0,0 @@
package org.gcube.application.framework.core.cache.factories;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.axis.message.addressing.Address;
import org.apache.axis.message.addressing.EndpointReference;
import org.apache.axis.message.addressing.EndpointReferenceType;
import org.gcube.application.framework.core.cache.RIsManager;
import org.gcube.application.framework.core.security.ServiceContextManager;
import org.gcube.application.framework.core.util.CacheEntryConstants;
import org.gcube.application.framework.core.util.QueryString;
import org.gcube.common.core.scope.GCUBEScope;
import org.gcube.common.core.utils.logging.GCUBELog;
import org.gcube.informationsystem.cache.SrvType;
import org.gcube.contentmanagement.contentlayer.contentmanagementservice.stubs.CMSPortType1PortType;
import org.gcube.contentmanagement.contentlayer.contentmanagementservice.stubs.DocumentDescription;
import org.gcube.contentmanagement.contentlayer.contentmanagementservice.stubs.DocumentPropertyDescription;
import org.gcube.contentmanagement.contentlayer.contentmanagementservice.stubs.GetDocumentParameters;
import org.gcube.contentmanagement.contentlayer.contentmanagementservice.stubs.service.CMSPortType1ServiceAddressingLocator;
import org.gcube.contentmanagement.layerindependent.descriptions.BasicInfoObjectDescription;
import net.sf.ehcache.constructs.blocking.CacheEntryFactory;
/**
* @author Valia Tsagkalidou (NKUA)
*
*/
public class ContentInfoCacheEntryFactory implements CacheEntryFactory {
/**
* An atomic integer to get the CMS EPRs round-robin
*/
protected static AtomicInteger cmsId = new AtomicInteger(0);
/** Object logger. */
protected final GCUBELog logger = new GCUBELog(this);
/**
* @param key a QueryString representing pairs of keys and values: needed keys are "vre" and "oid"
* @return a DocumentDescription as it is returned from the CMS. The content is not transfered for storage and efficiency reasons
*/
public Object createEntry(Object key) throws Exception {
QueryString query = (QueryString) key;
DocumentDescription docDescription = null;
if(query.containsKey(CacheEntryConstants.vre) && query.containsKey(CacheEntryConstants.oid))
{
EndpointReference[] cmsURIs = RIsManager.getInstance().getISCache(GCUBEScope.getScope(query.get(CacheEntryConstants.vre))).getEPRsFor("ContentManagement","ContentManagementService",SrvType.SIMPLE.name());
EndpointReferenceType serviceEPR = new EndpointReferenceType();
GetDocumentParameters docParams = new GetDocumentParameters();
docParams.setDocumentID(query.get(CacheEntryConstants.oid));
docParams.setTargetFileLocation(BasicInfoObjectDescription.RAW_CONTENT_DO_NOT_TRANSFER);
docParams.setUnrollLevels(3);
for(int i=0; i< cmsURIs.length; i++)
{
try
{
serviceEPR.setAddress(new Address(cmsURIs[cmsId.getAndIncrement()%cmsURIs.length].getAddress().toString()));
CMSPortType1ServiceAddressingLocator serviceLocator = new CMSPortType1ServiceAddressingLocator();
CMSPortType1PortType cms = serviceLocator.getCMSPortType1PortTypePort(serviceEPR);
cms = (CMSPortType1PortType) ServiceContextManager.applySecurity(cms, GCUBEScope.getScope(query.get(CacheEntryConstants.vre)), ApplicationCredentials.getInstance().getCredential(query.get(CacheEntryConstants.vre)));
docDescription = cms.getDocument(docParams);
long size = cms.getContentLength(query.get(CacheEntryConstants.oid));
DocumentPropertyDescription[] properties = docDescription.getProperties();
DocumentPropertyDescription[] newProperties = new DocumentPropertyDescription[properties.length + 1];
for(int j=0; j < properties.length; j++)
{
newProperties[j] = properties[j];
}
logger.debug("Size of file:" + size);
newProperties[properties.length] = new DocumentPropertyDescription("LengthOfRawContent", query.get(CacheEntryConstants.oid),"","" + size);
docDescription.setProperties(newProperties);
break;
}
catch (Exception e) {
logger.error("",e);
}
}
}
return docDescription;
}
}

View File

@ -6,10 +6,10 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.gcube.application.framework.core.genericresources.model.ISGenericResource;
import org.gcube.application.framework.core.util.CacheEntryConstants;
import org.gcube.application.framework.core.util.QueryString;
import org.gcube.application.framework.core.util.SessionConstants;
import org.gcube.application.framework.core.vremanagement.model.ISGenericResource;
import org.gcube.common.core.contexts.GCUBEContext;
import org.gcube.common.core.contexts.GHNContext;
import org.gcube.common.core.informationsystem.client.AtomicCondition;

View File

@ -1,103 +0,0 @@
package org.gcube.application.framework.core.cache.factories;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.axis.message.addressing.Address;
import org.apache.axis.message.addressing.EndpointReference;
import org.apache.axis.message.addressing.EndpointReferenceType;
import org.gcube.application.framework.core.cache.RIsManager;
import org.gcube.application.framework.core.security.ServiceContextManager;
import org.gcube.application.framework.core.util.CacheEntryConstants;
import org.gcube.application.framework.core.util.QueryString;
import org.gcube.common.core.scope.GCUBEScope;
import org.gcube.common.core.utils.logging.GCUBELog;
import org.gcube.informationsystem.cache.SrvType;
import org.gcube.metadatamanagement.metadatamanager.stubs.CreateManagerResponse;
import org.gcube.metadatamanagement.metadatamanager.stubs.GetElementItemResponse;
import org.gcube.metadatamanagement.metadatamanager.stubs.GetElementsResponse;
import org.gcube.metadatamanagement.metadatamanager.stubs.InformationObjectIDList;
import org.gcube.metadatamanagement.metadatamanager.stubs.MetadataManagerFactoryPortType;
import org.gcube.metadatamanagement.metadatamanager.stubs.MetadataManagerPortType;
import org.gcube.metadatamanagement.metadatamanager.stubs.MetadataObjectList;
import org.gcube.metadatamanagement.metadatamanager.stubs.service.MetadataManagerFactoryServiceAddressingLocator;
import org.gcube.metadatamanagement.metadatamanager.stubs.service.MetadataManagerServiceAddressingLocator;
import org.gcube.metadatamanagement.mmlibrary.model.BaseMetadata;
import net.sf.ehcache.constructs.blocking.CacheEntryFactory;
/**
* @author Valia Tsagkalidou (NKUA)
*
*/
public class MetadataCacheEntryFactory implements CacheEntryFactory {
/**
* An atomic integer to get the CMS EPRs round-robin
*/
protected static AtomicInteger mcId = new AtomicInteger(0);
/** Object logger. */
protected final GCUBELog logger = new GCUBELog(this);
/**
* @param key a QueryString representing pairs of keys and values. Needed keys are "vre", "metadataColID", "oid"
* @return the metadata object of the corresponding ID
*/
public Object createEntry(Object key) throws Exception {
QueryString query = (QueryString) key;
try {
MetadataManagerPortType metaManager = null;
EndpointReference[] mcURIs = RIsManager.getInstance().getISCache(GCUBEScope.getScope(query.get(CacheEntryConstants.vre))).getEPRsFor("MetadataManagement", "MetadataManager", SrvType.FACTORY.name());
logger.info("Number of available mms factories: " + mcURIs.length);
for(int i=0; i < mcURIs.length; i++)
{
try {
MetadataManagerServiceAddressingLocator instanceLocator = new MetadataManagerServiceAddressingLocator();
MetadataManagerFactoryPortType mcFactory = null;
EndpointReferenceType endpoint = new EndpointReferenceType();
endpoint.setAddress(new Address(mcURIs[mcId.getAndIncrement()%mcURIs.length].getAddress().toString()));
MetadataManagerFactoryServiceAddressingLocator mcflocator = new MetadataManagerFactoryServiceAddressingLocator();
mcFactory = mcflocator.getMetadataManagerFactoryPortTypePort(endpoint);
mcFactory = ServiceContextManager.applySecurity(mcFactory, GCUBEScope.getScope(query.get(CacheEntryConstants.vre)), ApplicationCredentials.getInstance().getCredential(query.get(CacheEntryConstants.vre)));
CreateManagerResponse createResponsefromcollection = mcFactory.createManagerFromCollection(query.get(CacheEntryConstants.metadataColID));
EndpointReferenceType instanceEPR = createResponsefromcollection.getEndpointReference();
metaManager = instanceLocator.getMetadataManagerPortTypePort(instanceEPR);
break;
}
catch (Exception e) {
logger.error("",e);
}
}
try {
metaManager = ServiceContextManager.applySecurity(metaManager, GCUBEScope.getScope(query.get(CacheEntryConstants.vre)), ApplicationCredentials.getInstance().getCredential(query.get(CacheEntryConstants.vre)));
} catch (Exception e) {
logger.error("",e);
}
logger.info("get metadata for oid: " + query.get(CacheEntryConstants.oid) + " and metadta col ID: " + query.get(CacheEntryConstants.metadataColID));
String[] oids = new String[1];
oids[0] = query.get(CacheEntryConstants.oid);
InformationObjectIDList oidsList = new InformationObjectIDList(oids);
GetElementsResponse elements = metaManager.getElements(oidsList);
for(int i=0; i < elements.getGetElementsItemResponse().length; i++)
{
GetElementItemResponse element = elements.getGetElementsItemResponse(i);
MetadataObjectList moList = element.getMetadataObjectList();
if (moList != null) {
for(int j=0; j < moList.getMetadataObject().length; j++)
{
String metadataXML = moList.getMetadataObject(0);
logger.debug("metadata:" + metadataXML);
if(metadataXML != null)
return metadataXML;
}
}
}
} catch (Exception e) {
logger.error("",e);
}
return null;
}
}

View File

@ -1,61 +0,0 @@
package org.gcube.application.framework.core.cache.factories;
import java.io.ByteArrayInputStream;
import java.util.concurrent.atomic.AtomicInteger;
import javax.xml.parsers.DocumentBuilderFactory;
import org.gcube.application.framework.core.commons.ProfileService;
import org.gcube.application.framework.core.util.CacheEntryConstants;
import org.gcube.application.framework.core.util.QueryString;
import org.gcube.common.core.scope.GCUBEScope;
import org.gcube.common.core.types.VOID;
import org.gcube.common.core.utils.logging.GCUBELog;
import org.gcube.personalization.userprofileaccess.stubs.UserProfileAccessPortType;
import org.gridforum.jgss.ExtendedGSSCredential;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import net.sf.ehcache.constructs.blocking.CacheEntryFactory;
/**
* @author Valia Tsagkalidou (NKUA)
*/
public class ProfileCacheEntryFactory implements CacheEntryFactory {
/**
* Document factory instance
*/
protected static final DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
/**
* An atomic integer to get the Profile EPRs round-robin
*/
protected static AtomicInteger profileId = new AtomicInteger(0);
/** Object logger. */
protected final GCUBELog logger = new GCUBELog(this);
/**
* @param key a QueryString representing pairs of keys and values. Needed keys are: "vre", "username"
* @return the user profile as a DOM object (Document)
*/
public Object createEntry(Object key) throws Exception {
QueryString query = (QueryString) key;
String profile = "";
if(query.containsKey(CacheEntryConstants.vre) && query.containsKey(CacheEntryConstants.username))
{
ProfileService profileService = new ProfileService(query.get(CacheEntryConstants.username), GCUBEScope.getScope(query.get(CacheEntryConstants.vre)));
ExtendedGSSCredential cred = ApplicationCredentials.getInstance().getCredential(query.get(CacheEntryConstants.vre));
UserProfileAccessPortType port = profileService.getUserProfileAccess(cred);
profile = port.getUserProfile(new VOID()); // this is the profile!!!
logger.debug(profile);
InputSource profileIn = new InputSource(new ByteArrayInputStream(profile.getBytes()));
Document profileDoc = dfactory.newDocumentBuilder().parse(profileIn);
return profileDoc;
}
return null;
}
}

View File

@ -1,123 +0,0 @@
package org.gcube.application.framework.core.cache.factories;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.xpath.XPathAPI;
import org.gcube.application.framework.core.cache.CachesManager;
import org.gcube.application.framework.core.util.CacheEntryConstants;
import org.gcube.application.framework.core.util.QueryString;
import org.gcube.application.framework.core.util.SessionConstants;
import org.gcube.application.framework.core.vremanagement.model.ISGenericResource;
import org.gcube.application.framework.core.commons.model.SearchField;
import org.gcube.common.core.utils.logging.GCUBELog;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import net.sf.ehcache.constructs.blocking.CacheEntryFactory;
/**
* @author Valia Tsagkalidou (NKUA)
*
*/
public class SchemaInfoCacheEntryFactory implements CacheEntryFactory {
/** Object logger. */
protected final GCUBELog logger = new GCUBELog(this);
/**
* Document factory instance
*/
public static final DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
/**
* @param key a String representing the VRE name.
* @return a HashMap that contains the Searchable Fields for each metadata schema
*/
public Object createEntry(Object key) throws Exception {
HashMap<String, List<SearchField>> SchemaHashMap = new HashMap<String, List<SearchField>>();
QueryString query = new QueryString();
query.addParameter(CacheEntryConstants.vre, key.toString());
query.addParameter(CacheEntryConstants.name, SessionConstants.MetadataSchemaInfo);
List<ISGenericResource> genericResources = ((List<ISGenericResource>)CachesManager.getInstance().getGenericResourceCache().get(query).getValue());
String schemaInfo = "<Records>";
for(ISGenericResource res : genericResources)
schemaInfo += "<Record>" + res.getBody() + "</Record>";
schemaInfo += "</Records>";
retrieveMetadataSchemaInfo(schemaInfo, SchemaHashMap);
return SchemaHashMap;
}
/**
* Retrieves the metadata schema info from DIS
*
* @param metaSchemata a serialized xml document containing the schemata together with their searchble fields
* @param SchemaHashMap a HashMap that contains the Searchable Fields for each metadata schema to be filled in
*/
protected void retrieveMetadataSchemaInfo(String metaSchemata, HashMap<String, List<SearchField>> SchemaHashMap) {
if(metaSchemata == null || metaSchemata.trim().equals(""))
return;
try {
InputSource metadata_in = new InputSource(new StringReader(metaSchemata));
Document doc = dfactory.newDocumentBuilder().parse(metadata_in);
NodeList res = doc.getElementsByTagName("Record");
int n = res.getLength();
int i;
for (int k = 0; k < n; k++)
{
//for each schema:
String schema = null;
List<SearchField> metaFields = new ArrayList<SearchField>();
schema = res.item(k).getChildNodes().item(0).getNodeName(); // schema name
System.out.println("schema=" + schema);
NodeList MetaRes = XPathAPI.selectNodeList(res.item(k), "//"+schema+"/option");
int mrLength = MetaRes.getLength();
for (i = 0; i < mrLength; i++)
{ // For each option (criterion):
try
{
NodeList res2 = MetaRes.item(i).getChildNodes();
int j, m;
m = res2.getLength();
SearchField option = new SearchField();
for (j = 0; j < m; j++)
{
String name = res2.item(j).getNodeName();
if (name.equals("option-name"))
{
option.name = res2.item(j).getFirstChild().getNodeValue();
}
else if (name.equals("option-value"))
{
option.value = res2.item(j).getFirstChild().getNodeValue();
}
else if (name.equals("option-type"))
{
option.type = res2.item(j).getFirstChild().getNodeValue();
}
else if (name.equals("option-sort"))
{
option.sort = res2.item(j).getFirstChild().getNodeValue();
}
}
metaFields.add(option);
}
catch (Exception e) {
e.printStackTrace();
}
}
SchemaHashMap.put(schema, metaFields);
}
}
catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -1,75 +0,0 @@
package org.gcube.application.framework.core.cache.factories;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.axis.message.addressing.Address;
import org.apache.axis.message.addressing.EndpointReference;
import org.apache.axis.message.addressing.EndpointReferenceType;
import org.gcube.application.framework.core.cache.RIsManager;
import org.gcube.application.framework.core.security.ServiceContextManager;
import org.gcube.common.core.scope.GCUBEScope;
import org.gcube.informationsystem.cache.SrvType;
import org.gcube.searchservice.searchmasterservice.stubs.SearchMasterPortType;
import org.gcube.searchservice.searchmasterservice.stubs.service.SearchMasterServiceAddressingLocator;
import net.sf.ehcache.constructs.blocking.CacheEntryFactory;
/**
* @author Valia Tsagkalidou (NKUA)
*/
public class SearchConfigCacheEntryFactory implements CacheEntryFactory {
/**
* An atomic integer to get the Search EPRs round-robin
*/
protected static AtomicInteger SMid = new AtomicInteger();
/**
* @param key a String representing the DL name.
* @return a String - serialized the search configuration
*/
public Object createEntry(Object key) throws Exception {
EndpointReference[] searchMasterURIs = null;
System.out.println("GenericResource: inside search config cache create entry starting..");
for(int count =0; count < 5 ; count++)
{
searchMasterURIs = RIsManager.getInstance().getISCache(GCUBEScope.getScope(key.toString())).getEPRsFor("Search", "SearchMaster", SrvType.SIMPLE.name());
if(searchMasterURIs.length > 0)
break;
Thread.sleep(5000);
}
// Creating a client for Search Master.
EndpointReferenceType serviceEPR = new EndpointReferenceType();
String collections_xml = null;
System.out.println(searchMasterURIs.length + " search masters found on IS.");
for(int counter = 0; counter < searchMasterURIs.length; counter++)
{
try
{
String search = searchMasterURIs[SMid.getAndIncrement()%searchMasterURIs.length].getAddress().toString();
System.out.println("search Master URL: " + search);
serviceEPR.setAddress(new Address(search));
SearchMasterServiceAddressingLocator serviceLocator = new SearchMasterServiceAddressingLocator();
SearchMasterPortType searchMaster = serviceLocator.getSearchMasterPortTypePort(serviceEPR);
try {
searchMaster = ServiceContextManager.applySecurity(searchMaster, GCUBEScope.getScope(key.toString()), ApplicationCredentials.getInstance().getCredential(key.toString()));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Retrieving dynamic configuration. E.g. which collections are
// currently available, if a Full text Index is available....
collections_xml = searchMaster.retrieveConfiguration("collections");
System.out.println("Search Configuration!!!" + collections_xml);
break;
}
catch (Exception e) {
e.printStackTrace();
}
}
return collections_xml;
}
}

View File

@ -1,299 +0,0 @@
package org.gcube.application.framework.core.cache.factories;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;
import javax.xml.rpc.ServiceException;
import org.apache.axis.message.addressing.Address;
import org.apache.axis.message.addressing.EndpointReference;
import org.apache.axis.message.addressing.EndpointReferenceType;
import org.apache.axis.types.URI.MalformedURIException;
import org.gcube.application.framework.core.cache.CachesManager;
import org.gcube.application.framework.core.cache.RIsManager;
import org.gcube.application.framework.core.security.ServiceContextManager;
import org.gcube.application.framework.core.util.CacheEntryConstants;
import org.gcube.application.framework.core.util.QueryString;
import org.gcube.application.framework.core.util.ThumbnailConstants;
import org.gcube.common.core.scope.GCUBEScope;
import org.gcube.common.core.scope.GCUBEScope.MalformedScopeExpressionException;
import org.gcube.common.core.utils.logging.GCUBELog;
import org.gcube.contentmanagement.contentlayer.contentmanagementservice.stubs.AlternativeRepresentationDescription;
import org.gcube.contentmanagement.contentlayer.contentmanagementservice.stubs.ArrayOfAlternativeRepresentation;
import org.gcube.contentmanagement.contentlayer.contentmanagementservice.stubs.CMSPortType1PortType;
import org.gcube.contentmanagement.contentlayer.contentmanagementservice.stubs.DocumentDescription;
import org.gcube.contentmanagement.contentlayer.contentmanagementservice.stubs.DocumentPropertyDescription;
import org.gcube.contentmanagement.contentlayer.contentmanagementservice.stubs.GetDocumentParameters;
import org.gcube.contentmanagement.contentlayer.contentmanagementservice.stubs.service.CMSPortType1ServiceAddressingLocator;
import org.gcube.contentmanagement.layerindependent.descriptions.BasicInfoObjectDescription;
import org.gcube.informationsystem.cache.SrvType;
import org.gcube.thumbnailer.stubs.ThumbnailerPortType;
import org.gcube.thumbnailer.stubs.TransformContent;
import org.gcube.thumbnailer.stubs.service.ThumbnailServiceAddressingLocator;
import org.ietf.jgss.GSSCredential;
import net.sf.ehcache.constructs.blocking.CacheEntryFactory;
/**
* @author Valia Tsagkalidou (NKUA)
*
*/
public class ThumbnailCacheEntryFactory implements CacheEntryFactory {
/** Object logger. */
protected final GCUBELog logger = new GCUBELog(this);
protected static AtomicInteger thumbId = new AtomicInteger(0);
/**
* @param key a QueryString representing pairs of keys and values.
* @return a Stream containing the thumbnail
*/
public Object createEntry(Object key) throws Exception {
QueryString query = (QueryString) key;
String vre = query.get(CacheEntryConstants.vre);
String oid = query.get(CacheEntryConstants.oid);
int width = Integer.parseInt(query.get(CacheEntryConstants.width));
int height = Integer.parseInt(query.get(CacheEntryConstants.height));
String[] thumbOptions = query.get(CacheEntryConstants.thumbOptions).split(",");
ArrayOfAlternativeRepresentation altRes;
List<String[]> thumbs = new ArrayList<String[]>();
CMSPortType1PortType cms = null;
int k =0;
while(true)
{
cms = getCMS(vre);
try
{
altRes = cms.getAlternativeRepresentations(oid);
}
catch (Exception e) {
k++;
if(k == 5)
break;
else
continue;
}
AlternativeRepresentationDescription[] docRes = altRes.getDocumentRepresentations();
if(docRes != null)
{
logger.debug("Found " + docRes.length + " alternative representations!!!");
for(int i=0; i < docRes.length; i++)
{
String toid = docRes[i].getRepresentationID();
if(docRes[i].getRepresentationRole().equals("thumbnail"))
{
logger.debug("Thumbnail Representation found: " + toid + "for object: " + oid + " description: " +docRes[i].getRepresenationDescription() + " role:" + docRes[i].getRepresentationRole());
QueryString newQuery = new QueryString();
newQuery.addParameter(CacheEntryConstants.vre, vre);
newQuery.addParameter(CacheEntryConstants.oid, toid);
DocumentDescription docDescription = (DocumentDescription) CachesManager.getInstance().getContentCache().get(newQuery).getValue();
DocumentPropertyDescription[] props = docDescription.getProperties();
logger.debug("Properties available: " + props.length);
String[] resolution = getResolution(props);
if(resolution != null)
thumbs.add(resolution);
}
}
}
break;
}
String thoid;
String[] thumbObj = findThumbnail(thumbs, thumbOptions, height, width);
if(thumbObj == null && !containOption(thumbOptions, ThumbnailConstants.FORCE_CREATE))
return null;
else if(thumbObj == null)
{
while(true)
{
ThumbnailerPortType stub = getThumb(vre);
TransformContent params = new TransformContent();
params.setOID(oid);
params.setHeight(width);
params.setWidth(height);
try
{
String tOid = stub.transformContent(params);
logger.debug("Object with id: " + oid + " was transformed to object " + tOid + "!");
thoid = tOid;
}
catch (Exception e) {
continue;
}
break;
}
}
else
thoid = thumbObj[2];
// The thumbnail existed or just created! Going to retrieve it from cms now!!!
GetDocumentParameters params = new GetDocumentParameters();
params.setDocumentID(thoid);
params.setTargetFileLocation(BasicInfoObjectDescription.RAW_CONTENT_IN_MESSAGE);
params.setUnrollLevels(3);
logger.debug("Calling cms to get the object");
DocumentDescription docDescr = cms.getDocument(params );
logger.debug("CMS call ended");
return docDescr.getRawContent();
}
private static ThumbnailerPortType getThumb(String vre) throws MalformedURIException,
ServiceException {
EndpointReference[] thumbURIs = null;
try {
thumbURIs = RIsManager.getInstance().getISCache(GCUBEScope.getScope(vre)).getEPRsFor("Portal","Thumbnailer-service",SrvType.SIMPLE.name());
} catch (Exception e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
String thumbAddress;
thumbAddress = thumbURIs[thumbId.getAndIncrement() % thumbURIs.length].getAddress().toString();
ThumbnailerPortType thumb;
EndpointReferenceType endpoint = new EndpointReferenceType();
endpoint.setAddress(new Address(thumbAddress));
ThumbnailServiceAddressingLocator thumblocator = new ThumbnailServiceAddressingLocator();
thumb = thumblocator.getThumbnailerPortTypePort(endpoint);
GSSCredential cred = ApplicationCredentials.getInstance().getCredential(vre);
try {
thumb = ServiceContextManager.applySecurity(thumb, GCUBEScope.getScope(vre), cred);
} catch (MalformedScopeExpressionException e) {
return null;
} catch (Exception e) {
return null;
}
return thumb;
}
private String[] findThumbnail(List<String[]> thumbs, String[] thumbOptions, int height, int width) {
if(thumbs == null || thumbs.size() == 0)
return null;
String[] res = null;
for(int i = 0; i < thumbs.size(); i++)
{
String[] thumbnail = thumbs.get(i);
int wThumb = Integer.parseInt(thumbnail[0]);
int hThumb = Integer.parseInt(thumbnail[1]);
if(containOption(thumbOptions, ThumbnailConstants.EQUAL))
{
if((height == hThumb && width >=wThumb)|| (height >= hThumb && width == wThumb))
return thumbnail;
}
else if(containOption(thumbOptions, ThumbnailConstants.FLOOR))
{
if(height >= hThumb && width >=wThumb)
{
if(res != null)
{
int w = Integer.parseInt(res[0]);
int h = Integer.parseInt(res[1]);
if(h < hThumb || w < wThumb)
res = thumbnail;
}
else
res = thumbnail;
}
}
else if(containOption(thumbOptions, ThumbnailConstants.CEIL))
{
logger.debug("hThumb= " + hThumb + " wThumb= " + wThumb);
if(height <= hThumb && width <=wThumb)
{
if(res != null)
{
int w = Integer.parseInt(res[0]);
int h = Integer.parseInt(res[1]);
logger.debug("h= " + h + " w= " + w);
if(h > hThumb || w > wThumb)
res = thumbnail;
}
else
res = thumbnail;
}
}
}
return res;
}
private boolean containOption(String[] thumbOptions, String option) {
for(int i=0; i < thumbOptions.length; i++)
{
if(thumbOptions[i].equals(option))
return true;
}
return false;
}
private String[] getResolution(DocumentPropertyDescription[] props) {
String[] resolution = new String[3];
int x = 0;
for(int i=0; i< props.length && x < 2; i++)
{
logger.debug("Property: " + props[i].getName() + " with value: " + props[i].getValue());
if(props[i].getName().equals("width"))
{
resolution[0] = props[i].getValue();
x++;
}
else if(props[i].getName().equals("height"))
{
resolution[1] = props[i].getValue();
x++;
}
}
resolution[2] = props[0].getObjectID();
if(x < 2)
return null;
else
return resolution;
}
protected static CMSPortType1PortType getCMS(String vre) throws MalformedURIException,
ServiceException {
EndpointReference[] cmsURIs = null;
try {
cmsURIs = RIsManager.getInstance().getISCache(GCUBEScope.getScope(vre)).getEPRsFor("ContentManagement","ContentManagementService",SrvType.SIMPLE.name());
} catch (Exception e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
boolean excep = true;
String cmsAddress;
Random random = new Random();
cmsAddress = cmsURIs[random.nextInt(cmsURIs.length)].getAddress().toString();
CMSPortType1PortType cms;
EndpointReferenceType endpoint = new EndpointReferenceType();
endpoint.setAddress(new Address(cmsAddress));
CMSPortType1ServiceAddressingLocator cmslocator = new CMSPortType1ServiceAddressingLocator();
cms = cmslocator.getCMSPortType1PortTypePort(endpoint);
try {
cms = ServiceContextManager.applySecurity(cms, GCUBEScope.getScope(vre), ApplicationCredentials.getInstance().getCredential(vre));
} catch (MalformedScopeExpressionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return cms;
}
}