use of org.apache.commons.collections.map.MultiValueMap in project alfresco-remote-api by Alfresco.
the class NodeApiTest method createContentWithAllParametersAccepted.
@Test
public void createContentWithAllParametersAccepted() throws Exception {
setRequestContext(user1);
// Let's start with creating a folder in our home folder.
String folderName = "My Folder" + GUID.generate();
// -my- (eg. User's Home for on-prem)
String myNodeId = getMyNodeId();
Folder folder = new Folder();
folder.setName(folderName);
folder.setNodeType(TYPE_CM_FOLDER);
HttpResponse response = post(getNodeChildrenUrl(myNodeId), toJsonAsStringNonNull(folder), 201);
Folder folderResponse = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class);
// Check the upload response
assertEquals(folderName, folderResponse.getName());
assertEquals(TYPE_CM_FOLDER, folderResponse.getNodeType());
// Let's now create an empty file within our home folder.
String fileName = "myfile" + GUID.generate() + ".txt";
Document document = new Document();
document.setName(fileName);
document.setNodeType(TYPE_CM_CONTENT);
response = post(getNodeChildrenUrl(myNodeId), toJsonAsStringNonNull(document), 201);
Document documentResponse = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
// Check the upload response
assertEquals(fileName, documentResponse.getName());
assertEquals(TYPE_CM_CONTENT, documentResponse.getNodeType());
// multipart/form-data upload with known parameters
/*
* case "name": case "filedata": case "autorename": case "nodetype":
* case "overwrite": case "majorversion": case "comment": case
* "relativepath": case "renditions":
*/
fileName = "quick-2.pdf";
File file = getResourceFile(fileName);
MultiPartBuilder multiPartBuilder = MultiPartBuilder.create().setFileData(new FileData(fileName, file));
multiPartBuilder.setAutoRename(true);
multiPartBuilder.setNodeType(TYPE_CM_CONTENT);
multiPartBuilder.setOverwrite(false);
multiPartBuilder.setMajorVersion(true);
multiPartBuilder.setDescription("test");
// multiPartBuilder.setRelativePath("/");
multiPartBuilder.setRenditions(Collections.singletonList("doclib"));
MultiPartRequest reqBody = multiPartBuilder.build();
response = post(getNodeChildrenUrl(myNodeId), reqBody.getBody(), null, reqBody.getContentType(), 201);
document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
ContentInfo contentInfo = document.getContent();
assertEquals(MimetypeMap.MIMETYPE_PDF, contentInfo.getMimeType());
assertEquals("UTF-8", contentInfo.getEncoding());
// multipart/form-data upload with unknown parameters
/*
*
* setPropeties custom
*/
document.setNodeType("custom:destination");
multiPartBuilder = MultiPartBuilder.create().setFileData(new FileData(fileName, file));
multiPartBuilder.setAutoRename(true);
multiPartBuilder.setNodeType("custom:destination");
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);
reqBody = multiPartBuilder.build();
response = post(getNodeChildrenUrl(myNodeId), reqBody.getBody(), null, reqBody.getContentType(), 201);
document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
contentInfo = document.getContent();
assertEquals(MimetypeMap.MIMETYPE_PDF, contentInfo.getMimeType());
assertEquals("UTF-8", contentInfo.getEncoding());
}
use of org.apache.commons.collections.map.MultiValueMap in project zm-mailbox by Zimbra.
the class BlobDeduper method deDupe.
private Pair<Integer, Long> deDupe(List<BlobReference> blobs) throws ServiceException {
int linksCreated = 0;
long sizeSaved = 0;
long srcInodeNum = 0;
String srcPath = null;
// check if there is any processed blob
for (BlobReference blob : blobs) {
if (blob.isProcessed()) {
String path = FileBlobStore.getBlobPath(blob.getMailboxId(), blob.getItemId(), blob.getRevision(), blob.getVolumeId());
try {
IO.FileInfo fileInfo = IO.fileInfo(path);
if (fileInfo != null) {
srcInodeNum = fileInfo.getInodeNum();
srcPath = path;
break;
}
} catch (IOException e) {
// ignore
}
}
}
if (srcInodeNum == 0) {
// check the path with maximum links
// organize the paths based on inode
MultiMap inodeMap = new MultiValueMap();
for (BlobReference blob : blobs) {
String path = FileBlobStore.getBlobPath(blob.getMailboxId(), blob.getItemId(), blob.getRevision(), blob.getVolumeId());
try {
IO.FileInfo fileInfo = IO.fileInfo(path);
if (fileInfo != null) {
inodeMap.put(fileInfo.getInodeNum(), path);
blob.setFileInfo(fileInfo);
}
} catch (IOException e) {
// ignore
}
}
// find inode which has maximum paths
int maxPaths = 0;
@SuppressWarnings("unchecked") Iterator<Map.Entry<Long, Collection<String>>> iter = inodeMap.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry<Long, Collection<String>> entry = iter.next();
if (entry.getValue().size() > maxPaths) {
maxPaths = entry.getValue().size();
srcInodeNum = entry.getKey();
srcPath = entry.getValue().iterator().next();
}
}
}
if (srcInodeNum == 0) {
return new Pair<Integer, Long>(0, Long.valueOf(0));
}
// First create a hard link for the source path, so that the file
// doesn't get deleted in the middle.
String holdPath = srcPath + "_HOLD";
File holdFile = new File(holdPath);
try {
IO.link(srcPath, holdPath);
// Now link the other paths to source path
for (BlobReference blob : blobs) {
if (blob.isProcessed()) {
continue;
}
String path = FileBlobStore.getBlobPath(blob.getMailboxId(), blob.getItemId(), blob.getRevision(), blob.getVolumeId());
try {
if (blob.getFileInfo() == null) {
blob.setFileInfo(IO.fileInfo(path));
}
} catch (IOException e) {
// ignore
}
if (blob.getFileInfo() == null) {
continue;
}
if (srcInodeNum == blob.getFileInfo().getInodeNum()) {
markBlobAsProcessed(blob);
continue;
}
// create the links for paths in two steps.
// first create a temp link and then rename it to actual path
// this guarantees that the file is always available.
String tempPath = path + "_TEMP";
File tempFile = new File(tempPath);
try {
IO.link(holdPath, tempPath);
File destFile = new File(path);
tempFile.renameTo(destFile);
markBlobAsProcessed(blob);
linksCreated++;
sizeSaved += blob.getFileInfo().getSize();
} catch (IOException e) {
ZimbraLog.misc.warn("Ignoring the error while deduping " + path, e);
} finally {
if (tempFile.exists()) {
tempFile.delete();
}
}
}
} catch (IOException e) {
ZimbraLog.misc.warn("Ignoring the error while creating a link for " + srcPath, e);
} finally {
// delete the hold file
if (holdFile.exists()) {
holdFile.delete();
}
}
return new Pair<Integer, Long>(linksCreated, sizeSaved);
}
use of org.apache.commons.collections.map.MultiValueMap in project BroadleafCommerce by BroadleafCommerce.
the class MvelTestUtils method executeTestCase.
private static boolean executeTestCase(Serializable exp, String val) {
final Map multiValueMap = new MultiValueMap();
multiValueMap.put(val, val);
final Level2 level2 = new Level2() {
@Override
public Map getMultiValueSkuAttributes() {
return multiValueMap;
}
};
Level1 level1 = new Level1() {
@Override
public Level2 getLevel2() {
return level2;
}
};
Map parameters = new HashMap();
parameters.put("level1", level1);
return (Boolean) MVEL.executeExpression(exp, parameters);
}
use of org.apache.commons.collections.map.MultiValueMap in project BroadleafCommerce by BroadleafCommerce.
the class PromotionMessageVariableExpression method getProductPromotionMessages.
public List<PromotionMessageDTO> getProductPromotionMessages(Product product, String... placements) {
List<String> filteredPlacements = filterInvalidPlacements(placements);
if (!filteredPlacements.contains(PromotionMessagePlacementType.EVERYWHERE.getType())) {
filteredPlacements.add(PromotionMessagePlacementType.EVERYWHERE.getType());
}
Map<String, List<PromotionMessageDTO>> promotionMessages = new MultiValueMap();
for (PromotionMessageGenerator generator : generators) {
promotionMessages.putAll(generator.generatePromotionMessages(product));
}
List<PromotionMessageDTO> filteredMessages = BLCPromotionMessageUtils.filterPromotionMessageDTOsByTypes(promotionMessages, filteredPlacements);
BLCPromotionMessageUtils.sortMessagesByPriority(filteredMessages);
return filteredMessages;
}
use of org.apache.commons.collections.map.MultiValueMap in project BroadleafCommerce by BroadleafCommerce.
the class PromotionMessageDTOServiceImpl method convertPromotionMessagesToDTOs.
@Override
public Map<String, List<PromotionMessageDTO>> convertPromotionMessagesToDTOs(Set<PromotionMessage> promotionMessages, Offer offer) {
MultiValueMap promotionMessageDTOs = new MultiValueMap();
for (PromotionMessage message : promotionMessages) {
PromotionMessageDTO dto = new PromotionMessageDTO(message);
CustomerRuleHolder customerRuleHolder = buildCustomerRuleHolder(offer);
dto.setCustomerRuleHolder(customerRuleHolder);
promotionMessageDTOs.put(dto.getMessagePlacement(), dto);
}
return promotionMessageDTOs;
}
Aggregations