throws AccessDenied, InconsistentParameters, InvalidHandle, InvalidRegistration, InvalidUserCategory,
MissingParameters, ModifyRegistrationRequired, OperationFailed, OperationNotSupported, ResourceSuspended
{
WSRP2ExceptionFactory.throwOperationFailedIfValueIsMissing(setPortletProperties, "SetPortletProperties");
PortletContext portletContext = setPortletProperties.getPortletContext();
WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(portletContext, "PortletContext", "SetPortletProperties");
PropertyList propertyList = setPortletProperties.getPropertyList();
WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(propertyList, "PropertyList", "SetPortletProperties");
Registration registration = producer.getRegistrationOrFailIfInvalid(setPortletProperties.getRegistrationContext());
checkUserAuthorization(setPortletProperties.getUserContext());
List<Property> properties = propertyList.getProperties();
properties = WSRPUtils.replaceByEmptyListIfNeeded(properties);
List<ResetProperty> resetProperties = propertyList.getResetProperties();
resetProperties = WSRPUtils.replaceByEmptyListIfNeeded(resetProperties);
int changesCount = 0;
if (ParameterValidation.existsAndIsNotEmpty(properties))
{
changesCount += properties.size();
// check that we don't set and reset the same property
if (ParameterValidation.existsAndIsNotEmpty(resetProperties))
{
List<QName> names = new ArrayList<QName>(WSRPUtils.transform(properties, new Function<Property, QName>()
{
public QName apply(Property from)
{
return from.getName();
}
}));
names.retainAll(WSRPUtils.transform(resetProperties, new Function<ResetProperty, QName>()
{
public QName apply(ResetProperty from)
{
return from.getName();
}
}));
if (!names.isEmpty())
{
WSRP2ExceptionFactory.throwWSException(InconsistentParameters.class,
"Attempted to set and reset at the same time the following properties: " + names, null);
}
}
}
if (ParameterValidation.existsAndIsNotEmpty(resetProperties))
{
changesCount += resetProperties.size();
}
if (changesCount > 0)
{
List<PropertyChange> changes = new ArrayList<PropertyChange>(changesCount);
if (properties != null)
{
for (Property property : properties)
{
String value = property.getStringValue();
// todo: deal with XML values...
// List<Object> values = property.getAny();
// todo: deal with language?
// String lang = property.getLang();
changes.add(PropertyChange.newUpdate(property.getName().toString(), value));
}
}
if (resetProperties != null)
{
for (ResetProperty resetProperty : resetProperties)
{
changes.add(PropertyChange.newReset(resetProperty.getName().toString()));
}
}
try
{
RegistrationLocal.setRegistration(registration);
org.gatein.pc.api.PortletContext resultContext =
producer.getPortletInvoker().setProperties(WSRPUtils.convertToPortalPortletContext(portletContext),
changes.toArray(new PropertyChange[changes.size()]));
return WSRPUtils.convertToWSRPPortletContext(resultContext);
}
catch (NoSuchPortletException e)
{
throw WSRP2ExceptionFactory.throwWSException(InvalidHandle.class, "Failed to set properties for portlet '" + portletContext.getPortletHandle() + "'", e);
}
catch (InvalidPortletIdException e)
{
throw WSRP2ExceptionFactory.throwWSException(InconsistentParameters.class, "Failed to set properties for portlet '" + portletContext.getPortletHandle() + "'", e);
}
catch (PortletInvokerException e)
{
throw WSRP2ExceptionFactory.throwWSException(OperationFailed.class, "Failed to set properties for portlet '" + portletContext.getPortletHandle() + "'", e);
}
finally
{
RegistrationLocal.setRegistration(null);
}