Package com.socialnetworkshirts.twittershirts.dataaccess.spreadshirt.http

Examples of com.socialnetworkshirts.twittershirts.dataaccess.spreadshirt.http.HttpCallCommand


    public ShopDTO getShop(String id)
            throws Exception {
        Element elem = shopCache.get(id);
        if (elem == null) {
            HttpCallCommand command =
                    commandFactory.createJaxbHttpCallCommand(shopUrl + "/" + id, HttpMethod.GET, null);
            command.execute();
            if (command.getStatus() >= 400) {
                throw new Exception("Could fetch shop xml!");
            }
            ShopDTO shop =
                    (ShopDTO) ((JAXBElement) command.getOutput()).getValue();
            shopCache.put(new Element(id, shop));
            return shop;
        }
        return (ShopDTO) elem.getObjectValue();
    }
View Full Code Here


    public CurrencyDTO getCurrency(String id)
            throws Exception {
        Element elem = currencyCache.get(id);
        if (elem == null) {
            HttpCallCommand command =
                    commandFactory.createJaxbHttpCallCommand(currencyUrl + "/" + id, HttpMethod.GET, null);
            command.execute();
            if (command.getStatus() >= 400) {
                throw new Exception("Could fetch currency xml!");
            }
            CurrencyDTO currency =
                    (CurrencyDTO) ((JAXBElement) command.getOutput()).getValue();
            currencyCache.put(new Element(id, currency));
            return currency;
        }
        return (CurrencyDTO) elem.getObjectValue();
    }
View Full Code Here

    public ProductTypeDTO getProductType(String id)
            throws Exception {
        Element elem = productTypeCache.get(id);
        if (elem == null) {
            HttpCallCommand getProductTypeCommand =
                    commandFactory.createJaxbHttpCallCommand(productTypeUrl + "/" + id, HttpMethod.GET, null);
            getProductTypeCommand.execute();
            if (getProductTypeCommand.getStatus() >= 400) {
                throw new Exception("Could not create product type xml!");
            }
            ProductTypeDTO productType =
                    (ProductTypeDTO) ((JAXBElement) getProductTypeCommand.getOutput()).getValue();
            productTypeCache.put(new Element(id, productType));
            return productType;
        }
        return (ProductTypeDTO) elem.getObjectValue();
View Full Code Here

    public PrintTypeDTO getPrintType(String id)
            throws Exception {
        Element elem = printTypeCache.get(id);
        if (elem == null) {
            HttpCallCommand getPrintTypeCommand =
                    commandFactory.createJaxbHttpCallCommand(printTypeUrl + "/" + id, HttpMethod.GET, null);
            getPrintTypeCommand.execute();
            if (getPrintTypeCommand.getStatus() >= 400) {
                throw new Exception("Could not create print type xml!");
            }
            PrintTypeDTO printType =
                    (PrintTypeDTO) ((JAXBElement) getPrintTypeCommand.getOutput()).getValue();
            printTypeCache.put(new Element(id, printType));
            return printType;
        }
        return (PrintTypeDTO) elem.getObjectValue();
    }
View Full Code Here

    public DesignDTO uploadDesign(Svg svg)
            throws Exception {
        Object obj = jaxbContext.createUnmarshaller()
                .unmarshal(this.getClass().getResourceAsStream("/design.xml"));
        // create design data using xml
        HttpCallCommand createDesignCommand =
                commandFactory.createJaxbHttpCallCommand(designUrl, HttpMethod.POST, null);
        createDesignCommand.setInput(obj);
        createDesignCommand.setApiKeyProtected(true);
        createDesignCommand.execute();
        if (createDesignCommand.getStatus() >= 400) {
            throw new Exception("Could not create design xml!");
        }

        // get created design xml
        HttpCallCommand getDesignCommand =
                commandFactory.createJaxbHttpCallCommand(createDesignCommand.getLocation(), HttpMethod.GET, null);
        getDesignCommand.execute();
        if (createDesignCommand.getStatus() >= 400) {
            throw new Exception("Could not retrieve design xml from " + createDesignCommand.getLocation() + "!");
        }
        DesignDTO design = (DesignDTO) ((JAXBElement) getDesignCommand.getOutput()).getValue();

        // determine upload location
        String uploadUrl = design.getResources().getResource().get(0).getHref();
        uploadUrl = uploadUrl.replace("3128", "2302");

        // upload image
        HttpCallCommand uploadDesignCommand =
                commandFactory.createSvgUploadCommand(uploadUrl, HttpMethod.PUT, null);
        uploadDesignCommand.setInput(svg);
        uploadDesignCommand.setApiKeyProtected(true);
        uploadDesignCommand.execute();
        if (uploadDesignCommand.getStatus() >= 400) {
            log.error(uploadDesignCommand.getErrorMessage());
            throw new Exception("Status above 400 expected but status was " + uploadDesignCommand.getStatus() + "!");
        }

        return design;
    }
View Full Code Here

            throws Exception {
        BasketDTO basket = objectFactory.createBasketDTO();
        /*Reference shopRef = objectFactory.createReference();
        shopRef.setId(shop.getId());
        basket.setShop(shopRef);*/
        HttpCallCommand command = commandFactory.createJaxbHttpCallCommand(basketsUrl, HttpMethod.POST, null);
        command.setApiKeyProtected(true);
        command.setInput(objectFactory.createBasket(basket));
        command.execute();
        log.info(command.getLocation());
        log.info("" + command.getStatus());
        log.info(command.getErrorMessage());
        if (command.getStatus() != 201)
            throw new IllegalArgumentException("Could not create Basket!");
        log.info("Basket location is: " + command.getLocation());
        return getBasket(command.getLocation().substring(command.getLocation().lastIndexOf("/") + 1));
    }
View Full Code Here

        return getBasket(command.getLocation().substring(command.getLocation().lastIndexOf("/") + 1));
    }

    public BasketDTO getBasket(String id)
            throws Exception {
        HttpCallCommand command =
                commandFactory.createJaxbHttpCallCommand(basketsUrl + "/" + id, HttpMethod.GET, null);
        command.setApiKeyProtected(true);
        command.execute();
        if (command.getStatus() != 200)
            throw new IllegalArgumentException("Could not retrieve basket!");
        return (BasketDTO) ((JAXBElement) command.getOutput()).getValue();
    }
View Full Code Here

        return (BasketDTO) ((JAXBElement) command.getOutput()).getValue();
    }

    public void updateBasket(BasketDTO basket)
            throws Exception {
        HttpCallCommand command =
                commandFactory.createJaxbHttpCallCommand(basketsUrl + "/" + basket.getId(), HttpMethod.PUT, null);
        command.setApiKeyProtected(true);
        command.setInput(objectFactory.createBasket(basket));
        command.execute();
        if (command.getStatus() != 200)
            throw new IllegalArgumentException("Could not create Basket!");
    }
View Full Code Here

            throw new IllegalArgumentException("Could not create Basket!");
    }

    public String getCheckoutUrl(String id)
            throws Exception {
        HttpCallCommand command =
                commandFactory.createJaxbHttpCallCommand(basketsUrl + "/" + id + "/checkout", HttpMethod.GET, null);
        command.setApiKeyProtected(true);
        command.execute();
        if (command.getStatus() != 200)
            throw new IllegalArgumentException("Could not retrieve checkout reference!");
        Reference reference = (Reference) ((JAXBElement) command.getOutput()).getValue();
        return reference.getHref();
    }
View Full Code Here

        return basketItem;
    }

    public String createProduct(ProductDTO product)
            throws Exception {
        HttpCallCommand createProductCommand =
                commandFactory.createJaxbHttpCallCommand(productUrl, HttpMethod.POST, null);
        // use id from fetched design xml here -> my solution is only a hack
        createProductCommand.setInput(objectFactory.createProduct(product));
        createProductCommand.setApiKeyProtected(true);
        createProductCommand.execute();
        if (createProductCommand.getStatus() >= 400) {
            throw new Exception("Could not create product xml!");
        }
        return createProductCommand.getLocation();
    }
View Full Code Here

TOP

Related Classes of com.socialnetworkshirts.twittershirts.dataaccess.spreadshirt.http.HttpCallCommand

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.