2009-08-17 19:32:15 +02:00
|
|
|
package org.gcube.informationsystem.collector.impl.porttypes;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.xml.namespace.QName;
|
|
|
|
|
|
|
|
import org.oasis.wsrf.faults.BaseFaultType;
|
|
|
|
|
|
|
|
import org.gcube.common.core.contexts.GCUBEServiceContext;
|
|
|
|
import org.gcube.common.core.porttypes.GCUBEPortType;
|
|
|
|
import org.gcube.common.core.utils.logging.GCUBELog;
|
|
|
|
import org.gcube.informationsystem.collector.impl.contexts.ICServiceContext;
|
2009-10-16 01:28:35 +02:00
|
|
|
import org.gcube.informationsystem.collector.impl.persistence.AggregatorPersistentResource;
|
2009-08-17 19:32:15 +02:00
|
|
|
import org.gcube.informationsystem.collector.impl.xmlstorage.exist.State;
|
|
|
|
import org.gcube.informationsystem.collector.impl.xmlstorage.exist.Sweeper;
|
|
|
|
import org.gcube.informationsystem.collector.stubs.DeleteProfileParams;
|
2009-10-16 01:28:35 +02:00
|
|
|
import org.gcube.informationsystem.collector.stubs.DocumentNotFoundFaultType;
|
|
|
|
import org.gcube.informationsystem.collector.stubs.GetProfileCriteria;
|
2009-11-20 23:53:10 +01:00
|
|
|
import org.gcube.informationsystem.collector.stubs.GetProfileLastModificationTimeMsCriteria;
|
2009-10-16 01:28:35 +02:00
|
|
|
import org.gcube.informationsystem.collector.stubs.GetResourceCriteria;
|
2009-11-20 23:53:10 +01:00
|
|
|
import org.gcube.informationsystem.collector.stubs.GetResourceLastModificationTimeMsCriteria;
|
2009-08-17 19:32:15 +02:00
|
|
|
|
|
|
|
import org.globus.wsrf.utils.FaultHelper;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* State service implementation class
|
|
|
|
*
|
|
|
|
* @author Manuele Simi (ISTI-CNR)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class XMLCollectionAccess extends GCUBEPortType {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* WS Properties namespace
|
|
|
|
*/
|
|
|
|
public static final QName RP_SET = new QName(
|
|
|
|
"http://gcube-system.org/namespaces/informationsystem/collector/XMLCollectionAccess",
|
|
|
|
"ICRP");
|
|
|
|
|
|
|
|
private final GCUBELog logger = new GCUBELog(XMLCollectionAccess.class);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes a profile from the Storage given its DILIGENT Resource ID
|
|
|
|
*
|
|
|
|
* @param params
|
|
|
|
* a stub class including private java.lang.String
|
|
|
|
* DILIGENTResourceID; the id of the profile to remove private
|
|
|
|
* java.lang.String profileType; the type of the profile to
|
|
|
|
* remove (e.g RunningInstance, DHN, Service, etc.);
|
|
|
|
* @return true if the resource is successfully deleted
|
|
|
|
* @throws BaseFaultType
|
|
|
|
* if the type parameter is not valid or an error occurs when
|
|
|
|
* deleting the profile
|
|
|
|
*/
|
|
|
|
|
|
|
|
public boolean deleteProfile(DeleteProfileParams params)
|
|
|
|
throws BaseFaultType {
|
|
|
|
|
|
|
|
boolean response = false;
|
|
|
|
String id = params.getID();
|
|
|
|
String type = params.getProfileType();
|
|
|
|
|
|
|
|
if ((id == "") || (id == null)) {
|
|
|
|
logger.warn("invalid id");
|
|
|
|
BaseFaultType fault = new BaseFaultType();
|
|
|
|
FaultHelper faultHelper = new FaultHelper(fault);
|
|
|
|
faultHelper.addDescription("invalid id");
|
|
|
|
throw fault;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((type == "") || (type == null)) {
|
|
|
|
logger.warn("invalid profile type");
|
|
|
|
BaseFaultType fault = new BaseFaultType();
|
|
|
|
FaultHelper faultHelper = new FaultHelper(fault);
|
|
|
|
faultHelper.addDescription("invalid profile type");
|
|
|
|
throw fault;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
logger.debug("deleting profile " + id + " from collection " + type);
|
2009-08-25 03:33:19 +02:00
|
|
|
State.getDataManager().retrieveAndDeleteProfileFromID(id, type);
|
2009-08-17 19:32:15 +02:00
|
|
|
if (type.equalsIgnoreCase("RunningInstance"))
|
|
|
|
Sweeper.cleanResourceForRI(id);
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("unable to remove resource: " + id, e);
|
|
|
|
BaseFaultType fault = new BaseFaultType();
|
|
|
|
FaultHelper faultHelper = new FaultHelper(fault);
|
|
|
|
faultHelper.addFaultCause(e);
|
|
|
|
faultHelper
|
|
|
|
.addDescription("IC service: Exception when deleting the requested resource");
|
|
|
|
throw fault;
|
|
|
|
}
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes a resource from the Storage given its ID
|
|
|
|
*
|
|
|
|
* @param id
|
|
|
|
* - the id of the resoure to remove
|
|
|
|
* @return true if the resource is successfully deleted
|
|
|
|
* @throws BaseFaultType
|
|
|
|
* if the id parameter is null or an error occurs when deleting
|
|
|
|
* the profile
|
|
|
|
*/
|
|
|
|
public boolean deleteResource(String id) throws BaseFaultType {
|
|
|
|
|
|
|
|
boolean response = false;
|
|
|
|
|
|
|
|
if ((id == "") || (id == null)) {
|
|
|
|
logger.warn("invalid id");
|
|
|
|
BaseFaultType fault = new BaseFaultType();
|
|
|
|
FaultHelper faultHelper = new FaultHelper(fault);
|
|
|
|
faultHelper.addDescription("invalid id");
|
|
|
|
throw fault;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
logger.debug("deleting resource: " + id);
|
2009-08-25 03:33:19 +02:00
|
|
|
State.getDataManager().retrieveAndDeleteResourceFromID(id);
|
2009-08-17 19:32:15 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("unable to remove resource: " + id, e);
|
|
|
|
BaseFaultType fault = new BaseFaultType();
|
|
|
|
FaultHelper faultHelper = new FaultHelper(fault);
|
|
|
|
faultHelper.addFaultCause(e);
|
|
|
|
faultHelper
|
|
|
|
.addDescription("IC service: Exception when deleting the requested resource");
|
|
|
|
throw fault;
|
|
|
|
}
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes the entire set of registered RPs from the storage
|
|
|
|
*
|
2009-11-20 23:53:10 +01:00
|
|
|
* @throws BaseFaultType if an error occurs when deleting the resources
|
2009-08-17 19:32:15 +02:00
|
|
|
*/
|
|
|
|
public void deleteAllRPs() throws BaseFaultType {
|
|
|
|
try {
|
|
|
|
logger.info("DeleteAllRPs operation invoked");
|
|
|
|
Sweeper.cleanRPs();
|
|
|
|
logger.info("All RPs have been deleted from the storage");
|
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("unable to clean RPs collction: ", e);
|
|
|
|
BaseFaultType fault = new BaseFaultType();
|
|
|
|
FaultHelper faultHelper = new FaultHelper(fault);
|
|
|
|
faultHelper.addFaultCause(e);
|
|
|
|
faultHelper.addDescription("IC service: Exception when deleting the requested resource");
|
|
|
|
throw fault;
|
|
|
|
}
|
2009-10-16 01:28:35 +02:00
|
|
|
}
|
2009-08-17 19:32:15 +02:00
|
|
|
|
2009-11-20 23:53:10 +01:00
|
|
|
/**
|
|
|
|
* Retrieves the given Resource
|
|
|
|
* @param criteria the Resource ID
|
|
|
|
* @return the XML serialization of the Resource
|
|
|
|
* @throws DocumentNotFoundFaultType if the Resource does not exist
|
|
|
|
*/
|
2009-10-16 01:28:35 +02:00
|
|
|
public String getResource(GetResourceCriteria criteria) throws DocumentNotFoundFaultType {
|
|
|
|
try {
|
2009-11-20 23:53:10 +01:00
|
|
|
AggregatorPersistentResource aresource = State.getDataManager().retrievePropertyResourceFromID(criteria.getID());
|
2009-10-16 01:28:35 +02:00
|
|
|
return aresource.getData();
|
2009-08-17 19:32:15 +02:00
|
|
|
} catch (Exception e) {
|
2009-10-16 01:28:35 +02:00
|
|
|
logger.warn("Unable to find Resource with ID=" + criteria.getID(), e);
|
|
|
|
throw new DocumentNotFoundFaultType();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-11-20 23:53:10 +01:00
|
|
|
/**
|
|
|
|
* Retrieves the given Profile
|
|
|
|
* @param criteria the Profile ID and Type
|
|
|
|
* @return the XML serialization of the Profile
|
|
|
|
* @throws DocumentNotFoundFaultType if the Profile does not exist
|
|
|
|
*/
|
2009-10-16 01:28:35 +02:00
|
|
|
public String getProfile(GetProfileCriteria criteria) throws DocumentNotFoundFaultType {
|
|
|
|
try {
|
2009-11-20 23:53:10 +01:00
|
|
|
AggregatorPersistentResource aresource = State.getDataManager().retrieveProfile(criteria.getID(), criteria.getProfileType());
|
2009-10-16 01:28:35 +02:00
|
|
|
return aresource.getData();
|
|
|
|
} catch (Exception e) {
|
|
|
|
logger.warn("Unable to find Profile with ID=" + criteria.getID(), e);
|
|
|
|
throw new DocumentNotFoundFaultType();
|
|
|
|
}
|
2009-08-17 19:32:15 +02:00
|
|
|
}
|
2009-08-27 00:57:18 +02:00
|
|
|
|
2009-11-20 23:53:10 +01:00
|
|
|
/**
|
|
|
|
* Gets the last modification time in milliseconds of the given Profile
|
|
|
|
* @param criteria the Profile ID and Type
|
|
|
|
* @return the last update time in milliseconds
|
|
|
|
* @throws DocumentNotFoundFaultType if the Profile does not exist
|
|
|
|
*/
|
|
|
|
public long getProfileLastModificationTimeMs(GetProfileLastModificationTimeMsCriteria criteria) throws DocumentNotFoundFaultType {
|
|
|
|
try {
|
|
|
|
AggregatorPersistentResource aresource = State.getDataManager().retrieveProfile(criteria.getID(), criteria.getProfileType());
|
|
|
|
return aresource.getLastUpdateTimeinMills();
|
|
|
|
} catch (Exception e) {
|
|
|
|
logger.warn("Unable to find Profile with ID=" + criteria.getID(), e);
|
|
|
|
throw new DocumentNotFoundFaultType();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the last modification time in milliseconds of the given Resource
|
|
|
|
* @param criteria the Resource ID
|
|
|
|
* @return the last update time in milliseconds
|
|
|
|
* @throws DocumentNotFoundFaultType if the Resource does not exist
|
|
|
|
*/
|
|
|
|
public long getResourceLastModificationTimeMs(GetResourceLastModificationTimeMsCriteria criteria) throws DocumentNotFoundFaultType {
|
|
|
|
try {
|
|
|
|
AggregatorPersistentResource aresource = State.getDataManager().retrievePropertyResourceFromID(criteria.getID());
|
|
|
|
return aresource.getLastUpdateTimeinMills();
|
|
|
|
} catch (Exception e) {
|
|
|
|
logger.warn("Unable to find Resource with ID=" + criteria.getID(), e);
|
|
|
|
throw new DocumentNotFoundFaultType();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-08-17 19:32:15 +02:00
|
|
|
/** {@inheritDoc} */
|
|
|
|
@Override
|
|
|
|
protected GCUBEServiceContext getServiceContext() {
|
|
|
|
return ICServiceContext.getContext();
|
|
|
|
}
|
|
|
|
}
|