Search in sources :

Example 6 with MultiValueMap

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());
}
Also used : MultiPartBuilder(org.alfresco.rest.api.tests.util.MultiPartBuilder) ContentInfo(org.alfresco.rest.api.tests.client.data.ContentInfo) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) MultiPartRequest(org.alfresco.rest.api.tests.util.MultiPartBuilder.MultiPartRequest) Folder(org.alfresco.rest.api.tests.client.data.Folder) Document(org.alfresco.rest.api.tests.client.data.Document) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) FileData(org.alfresco.rest.api.tests.util.MultiPartBuilder.FileData) MultiValueMap(org.apache.commons.collections.map.MultiValueMap) Test(org.junit.Test) AbstractSingleNetworkSiteTest(org.alfresco.rest.AbstractSingleNetworkSiteTest)

Example 7 with MultiValueMap

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);
}
Also used : IO(com.zimbra.znative.IO) IOException(java.io.IOException) MultiMap(org.apache.commons.collections.MultiMap) Collection(java.util.Collection) LinkedHashMap(java.util.LinkedHashMap) MultiValueMap(org.apache.commons.collections.map.MultiValueMap) Map(java.util.Map) MultiMap(org.apache.commons.collections.MultiMap) File(java.io.File) MultiValueMap(org.apache.commons.collections.map.MultiValueMap) Pair(com.zimbra.common.util.Pair)

Example 8 with MultiValueMap

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);
}
Also used : HashMap(java.util.HashMap) HashMap(java.util.HashMap) MultiValueMap(org.apache.commons.collections.map.MultiValueMap) Map(java.util.Map) MultiValueMap(org.apache.commons.collections.map.MultiValueMap)

Example 9 with MultiValueMap

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;
}
Also used : PromotionMessageGenerator(org.broadleafcommerce.core.promotionMessage.service.PromotionMessageGenerator) PromotionMessageDTO(org.broadleafcommerce.core.promotionMessage.dto.PromotionMessageDTO) ArrayList(java.util.ArrayList) List(java.util.List) MultiValueMap(org.apache.commons.collections.map.MultiValueMap)

Example 10 with MultiValueMap

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;
}
Also used : PromotionMessage(org.broadleafcommerce.core.promotionMessage.domain.PromotionMessage) CustomerRuleHolder(org.broadleafcommerce.profile.core.dto.CustomerRuleHolder) PromotionMessageDTO(org.broadleafcommerce.core.promotionMessage.dto.PromotionMessageDTO) MultiValueMap(org.apache.commons.collections.map.MultiValueMap)

Aggregations

MultiValueMap (org.apache.commons.collections.map.MultiValueMap)12 Map (java.util.Map)5 HashMap (java.util.HashMap)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 MultiMap (org.apache.commons.collections.MultiMap)3 IOException (java.io.IOException)2 RandomAccessFile (java.io.RandomAccessFile)2 LinkedHashMap (java.util.LinkedHashMap)2 AbstractSingleNetworkSiteTest (org.alfresco.rest.AbstractSingleNetworkSiteTest)2 HttpResponse (org.alfresco.rest.api.tests.client.HttpResponse)2 Document (org.alfresco.rest.api.tests.client.data.Document)2 MultiPartBuilder (org.alfresco.rest.api.tests.util.MultiPartBuilder)2 FileData (org.alfresco.rest.api.tests.util.MultiPartBuilder.FileData)2 MultiPartRequest (org.alfresco.rest.api.tests.util.MultiPartBuilder.MultiPartRequest)2 PromotionMessageDTO (org.broadleafcommerce.core.promotionMessage.dto.PromotionMessageDTO)2 Test (org.junit.Test)2 ServiceDescriptor (com.emc.sa.descriptor.ServiceDescriptor)1 ServiceField (com.emc.sa.descriptor.ServiceField)1