75 lines
2.6 KiB
Java
75 lines
2.6 KiB
Java
package org.gcube.portlets.widgets.mpformbuilder.server;
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
import java.io.InputStream;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
|
import org.gcube.portlets.widgets.mpformbuilder.client.MetadataProfileFormBuilderService;
|
|
import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetaDataProfileBean;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
|
|
|
/**
|
|
* The server side implementation of the RPC service.
|
|
*/
|
|
@SuppressWarnings("serial")
|
|
public class MetadataProfileFormBuilderServiceImpl extends RemoteServiceServlet
|
|
implements MetadataProfileFormBuilderService {
|
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(MetadataProfileFormBuilderServiceImpl.class);
|
|
|
|
/**
|
|
* Escape an html string. Escaping data received from the client helps to
|
|
* prevent cross-site script vulnerabilities.
|
|
*
|
|
* @param html the html string to escape
|
|
* @return the escaped string
|
|
*/
|
|
private String escapeHtml(String html) {
|
|
if (html == null) {
|
|
return null;
|
|
}
|
|
return html.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">");
|
|
}
|
|
|
|
@Override
|
|
public List<MetaDataProfileBean> getProfilesInTheScope(String scope,String genericResourceSecondaryType) throws Exception {
|
|
LOG.info("Called getProfilesInTheScope with parameter scope: " +scope+ ", genericResourceSecondaryType: "+genericResourceSecondaryType);
|
|
|
|
if(genericResourceSecondaryType==null || genericResourceSecondaryType.isEmpty())
|
|
throw new Exception("The input parameter 'genericResourceSecondaryType' is not valid");
|
|
|
|
List<MetaDataProfileBean> toReturn = new ArrayList<MetaDataProfileBean>();
|
|
try {
|
|
|
|
String evaluatedScope = scope == null || scope.isEmpty()?ScopeProvider.instance.get():scope;
|
|
LOG.debug("Evaluated scope is " + scope);
|
|
toReturn = MetadataDiscovery.getMetadataProfilesList(evaluatedScope, genericResourceSecondaryType);
|
|
} catch (Exception e) {
|
|
LOG.error("Failed to retrieve profiles for scope " +scope, e);
|
|
throw e;
|
|
}
|
|
|
|
return toReturn;
|
|
}
|
|
|
|
@Override
|
|
public MetaDataProfileBean getProfileForMetadata(String metadata) throws Exception {
|
|
LOG.info("Called getProfileForMetadata with parameter metadata: " + metadata);
|
|
MetaDataProfileBean toReturn = null;
|
|
try {
|
|
InputStream targetStream = new ByteArrayInputStream(metadata.getBytes());
|
|
toReturn = MetadataDiscovery.getMetadataProfile(targetStream);
|
|
} catch (Exception e) {
|
|
LOG.error("Failed to retrieve profile for metadata " +metadata, e);
|
|
throw e;
|
|
}
|
|
|
|
return toReturn;
|
|
}
|
|
}
|