use of org.apache.commons.collections.map.MultiValueMap in project openmrs-core by openmrs.
the class PropertiesFileValidator method getAsPropertiesKeyValueMultiMap.
private MultiMap getAsPropertiesKeyValueMultiMap(List<String> fileLines) {
MultiMap multiMap = new MultiValueMap();
for (String line : fileLines) {
if (isCorectKeyValueLine(line)) {
Map.Entry<String, String> tuple = extractKeyValue(line);
multiMap.put(tuple.getKey(), tuple.getValue());
}
}
return multiMap;
}
use of org.apache.commons.collections.map.MultiValueMap in project alfresco-remote-api by Alfresco.
the class NodeApiTest method updatePropertiesMultivalueTest.
@Test
public void updatePropertiesMultivalueTest() throws Exception {
setRequestContext(user1);
String myNodeId = getMyNodeId();
// create a multiple-value field from multipart\formdata
String fileName = "myfile" + GUID.generate() + ".txt";
File file = getResourceFile("quick-2.pdf");
MultiPartBuilder multiPartBuilder = MultiPartBuilder.create().setFileData(new FileData(fileName, file));
multiPartBuilder.setAutoRename(true);
multiPartBuilder.setNodeType("custom:destination");
multiPartBuilder.setOverwrite(false);
multiPartBuilder.setMajorVersion(true);
multiPartBuilder.setDescription("test");
multiPartBuilder.setRenditions(Collections.singletonList("doclib"));
Map<String, String> props = new MultiValueMap();
props.put("cm:title", "test title");
props.put("custom:locations", "loc1");
props.put("custom:locations", "loc2");
props.put("custom:locations", "loc3");
multiPartBuilder.setProperties(props);
MultiPartRequest reqBody = multiPartBuilder.build();
HttpResponse response = post(getNodeChildrenUrl(myNodeId), reqBody.getBody(), null, reqBody.getContentType(), 201);
Document documentResponse = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
// build the multiple-value as json array
String jsonUpdate = "{" + "\"name\":\"My Other Folder\"," + "\"nodeType\":\"custom:destination\"," + "\"properties\":" + "{" + "\"cm:title\":\"Folder title\"," + "\"cm:description\":\"This is an important folder\"," + "\"custom:locations\":[" + "\"location X\"," + "\"location Y\"" + "]" + "}" + "}";
response = put(URL_NODES, documentResponse.getId(), jsonUpdate, null, 200);
Node nodeUpdateResponse = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
Map<String, Object> propUpdateResponse = nodeUpdateResponse.getProperties();
assertNotNull(propUpdateResponse.get("custom:locations"));
assertTrue(((ArrayList) (propUpdateResponse.get("custom:locations"))).size() == 2);
// build the multiple-value as array
Map<String, Object> properties = new HashMap();
List locations = new ArrayList<String>();
locations.add("location X1");
properties.put("custom:locations", locations);
Node nodeUpdate = new Node();
nodeUpdate.setProperties(properties);
response = put(URL_NODES, documentResponse.getId(), toJsonAsStringNonNull(nodeUpdate), null, 200);
nodeUpdateResponse = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
propUpdateResponse = nodeUpdateResponse.getProperties();
assertNotNull(propUpdateResponse.get("custom:locations"));
assertTrue(((ArrayList) (propUpdateResponse.get("custom:locations"))).size() == 1);
}
use of org.apache.commons.collections.map.MultiValueMap in project coprhd-controller by CoprHD.
the class WorkflowServiceDescriptor method mapWorkflowToServiceDescriptor.
private ServiceDescriptor mapWorkflowToServiceDescriptor(final CustomServicesWorkflow from) {
final ServiceDescriptor to = new ServiceDescriptor();
try {
final CustomServicesWorkflowDocument wfDocument = WorkflowHelper.toWorkflowDocument(from);
if (StringUtils.isEmpty(from.getState()) || from.getState().equals(CustomServicesWorkflowStatus.NONE) || from.getState().equals(CustomServicesWorkflowStatus.INVALID)) {
log.error("Workflow state is not valid. State:{} Workflow name:{}", from.getState(), from.getLabel());
throw new IllegalStateException(String.format("Workflow state is not valid. State %s Workflow name: %s Workflow id: %s", from.getState(), from.getLabel(), from.getId()));
}
to.setCategory(CUSTOM_SERVICE_CATEGORY);
to.setDescription(StringUtils.isNotBlank(wfDocument.getDescription()) ? wfDocument.getDescription() : wfDocument.getName());
to.setDestructive(false);
final String wfID = URIUtil.asString(from.getId());
to.setServiceId(StringUtils.isNotBlank(wfID) ? wfID : wfDocument.getName());
to.setTitle(wfDocument.getName());
to.setWorkflowId(wfDocument.getName());
to.setRoles(new ArrayList<String>(Arrays.asList(Role.SYSTEM_ADMIN.toString())));
for (final Step step : wfDocument.getSteps()) {
if (null != step.getInputGroups()) {
// Looping through all input groups
for (final InputGroup inputGroup : step.getInputGroups().values()) {
final MultiValueMap tableMap = new MultiValueMap();
for (final Input wfInput : inputGroup.getInputGroup()) {
final ServiceField serviceField = new ServiceField();
if (CustomServicesConstants.InputType.FROM_USER.toString().equals(wfInput.getType())) {
serviceField.setType(wfInput.getInputFieldType());
} else if (CustomServicesConstants.InputType.ASSET_OPTION_SINGLE.toString().equals(wfInput.getType())) {
serviceField.setType(wfInput.getValue());
} else if (CustomServicesConstants.InputType.ASSET_OPTION_MULTI.toString().equals(wfInput.getType())) {
serviceField.setType(wfInput.getValue());
serviceField.setSelect(ServiceField.SELECT_MANY);
} else if (CustomServicesConstants.InputType.FROM_USER_MULTI.toString().equals(wfInput.getType())) {
serviceField.setType(ServiceField.TYPE_CHOICE);
if (StringUtils.isNotBlank(wfInput.getDefaultValue())) {
// For list of options
final Map<String, String> options = new HashMap<>();
final List<String> defaultList = Arrays.asList(wfInput.getDefaultValue().split(","));
for (final String value : defaultList) {
// making the key and value the same
options.put(value, value);
}
serviceField.setOptions(options);
serviceField.setInitialValue(options.get(defaultList.get(0)));
} else if (MapUtils.isNotEmpty(wfInput.getOptions())) {
// For options Map
serviceField.setOptions(wfInput.getOptions());
}
} else {
continue;
}
final String inputName = wfInput.getName();
if (StringUtils.isNotBlank(wfInput.getDescription())) {
serviceField.setDescription(wfInput.getDescription());
}
final String friendlyName = StringUtils.isBlank(wfInput.getFriendlyName()) ? inputName : wfInput.getFriendlyName();
serviceField.setLabel(friendlyName);
serviceField.setName(friendlyName.replaceAll(CustomServicesConstants.SPACES_REGEX, StringUtils.EMPTY));
serviceField.setRequired(wfInput.getRequired());
if (!(CustomServicesConstants.InputType.FROM_USER_MULTI.toString().equals(wfInput.getType()))) {
// Initial value already set for FROM_USER_MULTI
serviceField.setInitialValue(wfInput.getDefaultValue());
}
// Setting all unlocked fields as lockable
if (!wfInput.getLocked()) {
serviceField.setLockable(true);
}
// if there is a table name we will build ServiceFieldTable later
if (null != wfInput.getTableName()) {
tableMap.put(wfInput.getTableName(), serviceField);
} else {
to.getItems().put(friendlyName, serviceField);
}
}
for (final String table : (Set<String>) tableMap.keySet()) {
final ServiceFieldTable serviceFieldTable = new ServiceFieldTable();
serviceFieldTable.setType(ServiceItem.TYPE_TABLE);
serviceFieldTable.setLabel(table);
serviceFieldTable.setName(table);
for (final ServiceField serviceField : (List<ServiceField>) tableMap.getCollection(table)) {
serviceFieldTable.addItem(serviceField);
}
to.getItems().put(table, serviceFieldTable);
}
}
}
}
} catch (final IOException io) {
log.error("Error deserializing workflow", io);
throw new IllegalStateException(String.format("Error deserializing workflow %s", from.getLabel()));
}
log.debug("Mapped workflow service descriptor for {}", from.getLabel());
return to;
}
use of org.apache.commons.collections.map.MultiValueMap in project wso2-synapse by wso2.
the class ServerWorker method createMessageContext.
/**
* Create an Axis2 message context for the given http request. The request may be in the
* process of being streamed
* @param request the http request to be used to create the corresponding Axis2 message context
* @return the Axis2 message context created
*/
private MessageContext createMessageContext(HttpRequest request) {
MessageContext msgContext = new MessageContext();
msgContext.setMessageID(UIDGenerator.generateURNString());
// There is a discrepency in what I thought, Axis2 spawns a new threads to
// send a message if this is TRUE - and I want it to be the other way
msgContext.setProperty(MessageContext.CLIENT_API_NON_BLOCKING, Boolean.FALSE);
msgContext.setConfigurationContext(cfgCtx);
if ("https".equalsIgnoreCase(schemeName)) {
msgContext.setTransportOut(cfgCtx.getAxisConfiguration().getTransportOut(Constants.TRANSPORT_HTTPS));
msgContext.setTransportIn(cfgCtx.getAxisConfiguration().getTransportIn(Constants.TRANSPORT_HTTPS));
msgContext.setIncomingTransportName(Constants.TRANSPORT_HTTPS);
SSLIOSession session = (SSLIOSession) (conn.getContext()).getAttribute(SSLIOSession.SESSION_KEY);
// set SSL certificates to message context if SSLVerifyClient parameter is set
if (session != null && msgContext.getTransportIn() != null && msgContext.getTransportIn().getParameter(NhttpConstants.SSL_VERIFY_CLIENT) != null) {
try {
msgContext.setProperty(NhttpConstants.SSL_CLIENT_AUTH_CERT_X509, session.getSSLSession().getPeerCertificateChain());
} catch (SSLPeerUnverifiedException e) {
// Peer Certificate Chain may not be available always.(in case of verify client is optional)
if (log.isTraceEnabled()) {
log.trace("Peer certificate chain is not available for MsgContext " + msgContext.getMessageID());
}
}
}
} else {
msgContext.setTransportOut(cfgCtx.getAxisConfiguration().getTransportOut(Constants.TRANSPORT_HTTP));
msgContext.setTransportIn(cfgCtx.getAxisConfiguration().getTransportIn(Constants.TRANSPORT_HTTP));
msgContext.setIncomingTransportName(Constants.TRANSPORT_HTTP);
}
msgContext.setProperty(Constants.OUT_TRANSPORT_INFO, this);
// the following statement causes the soap session services to be failing - ruwan
// msgContext.setServiceGroupContextId(UUIDGenerator.getUUID());
msgContext.setServerSide(true);
msgContext.setProperty(Constants.Configuration.TRANSPORT_IN_URL, request.getRequestLine().getUri());
// http transport header names are case insensitive
Map<String, String> headers = new TreeMap<String, String>(new Comparator<String>() {
public int compare(String o1, String o2) {
return o1.compareToIgnoreCase(o2);
}
});
for (Header header : request.getAllHeaders()) {
String headerName = header.getName();
// if this header is already added
if (headers.containsKey(headerName)) {
/* this is a multi-value header */
// generate the key
String key = NhttpConstants.EXCESS_TRANSPORT_HEADERS;
// get the old value
String oldValue = headers.get(headerName);
// adds additional values to a list in a property of message context
Map map;
if (msgContext.getProperty(key) != null) {
map = (Map) msgContext.getProperty(key);
map.put(headerName, oldValue);
} else {
map = new MultiValueMap();
map.put(headerName, oldValue);
// set as a property in message context
msgContext.setProperty(key, map);
}
}
headers.put(header.getName(), header.getValue());
}
msgContext.setProperty(MessageContext.TRANSPORT_HEADERS, headers);
// find the remote party IP address and set it to the message context
if (conn instanceof HttpInetConnection) {
HttpContext httpContext = conn.getContext();
HttpInetConnection inetConn = (HttpInetConnection) conn;
InetAddress remoteAddr = inetConn.getRemoteAddress();
if (remoteAddr != null) {
httpContext.setAttribute(NhttpConstants.CLIENT_REMOTE_ADDR, remoteAddr);
httpContext.setAttribute(NhttpConstants.CLIENT_REMOTE_PORT, inetConn.getRemotePort());
msgContext.setProperty(MessageContext.REMOTE_ADDR, remoteAddr.getHostAddress());
msgContext.setProperty(NhttpConstants.REMOTE_HOST, NhttpUtil.getHostName(remoteAddr));
remoteAddress = remoteAddr.getHostAddress();
}
}
msgContext.setProperty(RequestResponseTransport.TRANSPORT_CONTROL, new HttpCoreRequestResponseTransport(msgContext));
msgContext.setProperty(ServerHandler.SERVER_CONNECTION_DEBUG, conn.getContext().getAttribute(ServerHandler.SERVER_CONNECTION_DEBUG));
msgContext.setProperty(NhttpConstants.NHTTP_INPUT_STREAM, is);
msgContext.setProperty(NhttpConstants.NHTTP_OUTPUT_STREAM, os);
return msgContext;
}
use of org.apache.commons.collections.map.MultiValueMap in project wso2-synapse by wso2.
the class ClientHandler method setHeaders.
private void setHeaders(HttpContext context, HttpResponse response, MessageContext outMsgCtx, MessageContext responseMsgCtx) {
Header[] headers = response.getAllHeaders();
if (headers != null && headers.length > 0) {
Map<String, String> headerMap = new TreeMap<String, String>(new Comparator<String>() {
public int compare(String o1, String o2) {
return o1.compareToIgnoreCase(o2);
}
});
String endpointURLPrefix = (String) context.getAttribute(NhttpConstants.ENDPOINT_PREFIX);
String servicePrefix = (String) outMsgCtx.getProperty(NhttpConstants.SERVICE_PREFIX);
for (int i = 0; i < headers.length; i++) {
Header header = headers[i];
// if this header is already added
if (headerMap.containsKey(header.getName())) {
/* this is a multi-value header */
// generate the key
String key = NhttpConstants.EXCESS_TRANSPORT_HEADERS;
// get the old value
String oldValue = headerMap.get(header.getName());
// adds additional values to a list in a property of message
// context
Map map;
if (responseMsgCtx.getProperty(key) != null) {
map = (Map) responseMsgCtx.getProperty(key);
map.put(header.getName(), oldValue);
} else {
map = new MultiValueMap();
map.put(header.getName(), oldValue);
// set as a property in message context
responseMsgCtx.setProperty(key, map);
}
}
if ("Location".equals(header.getName()) && endpointURLPrefix != null && servicePrefix != null) {
// name and the port.
try {
URI serviceURI = new URI(servicePrefix);
URI endpointURI = new URI(endpointURLPrefix);
URI locationURI = new URI(header.getValue());
if (locationURI.getHost().equalsIgnoreCase(endpointURI.getHost())) {
URI newURI = new URI(locationURI.getScheme(), locationURI.getUserInfo(), serviceURI.getHost(), serviceURI.getPort(), locationURI.getPath(), locationURI.getQuery(), locationURI.getFragment());
headerMap.put(header.getName(), newURI.toString());
responseMsgCtx.setProperty(NhttpConstants.SERVICE_PREFIX, outMsgCtx.getProperty(NhttpConstants.SERVICE_PREFIX));
}
} catch (URISyntaxException e) {
log.error(e.getMessage(), e);
}
} else {
headerMap.put(header.getName(), header.getValue());
}
}
responseMsgCtx.setProperty(MessageContext.TRANSPORT_HEADERS, headerMap);
}
}
Aggregations