Package org.sakaiproject.entitybus.exception

Examples of org.sakaiproject.entitybus.exception.EntityEncodingException


                    entity = internalInputTranslator(ref, format, inputStream, null);
                }

                if (entity == null) {
                    // FAILURE input could not be translated into an entity object
                    throw new EntityEncodingException("Unable to translate entity ("+ref+") with format ("
                            +format+"), translated entity object was null", ref+"");
                }
            } else {
                // format type not handled
                throw new FormatUnsupportedException("Inputable restriction for "
View Full Code Here


                        if (params != null && params.size() > 0) {
                            entity = current;
                            try {
                                ReflectUtils.getInstance().populateFromParams(entity, params);
                            } catch (RuntimeException e) {
                                throw new EntityEncodingException("Unable to populate bean for ref ("+ref+") from request: " + e.getMessage(), ref+"", e);
                            }
                        } else {
                            // no request params, bad request
                            throw new EntityException("No request params for html input request (there must be at least one) for reference: " + ref,
                                    ref.toString(), HttpServletResponse.SC_BAD_REQUEST);
                        }
                    }
                } else {
                    // all other formats
                    if (input == null) {
                        // no request params, bad request
                        throw new EntityException("No input for input translation (input cannot be null) for reference: " + ref,
                                ref.toString(), HttpServletResponse.SC_BAD_REQUEST);
                    } else {
                        String data = StringUtils.makeStringFromInputStream(input);
                        Map<String, Object> decoded = null;
                        try {
                            decoded = decodeData(data, format);
                        } catch (IllegalArgumentException iae) {
                            throw new EntityEncodingException("No encoder available for the given format ("+format+"), ref=" + ref + ":" + iae.getMessage(), ref.toString(), iae);
                        } catch (UnsupportedOperationException uoe) {
                            throw new EntityEncodingException("Failure during internal input encoding of entity: " + ref + " to format ("+format+"):" + uoe.getMessage(), ref.toString(), uoe);
                        }
                        entity = current;
                        // handle the special case where the JSON was created by xstream or something else that puts the data inside an object with a "root"
                        if (decoded.size() == 1 && decoded.containsKey(ref.getPrefix())) {
                            Object o = decoded.get(ref.getPrefix());
                            if (o instanceof Map) {
                                decoded = (Map<String, Object>) o;
                            }
                        }
                        try {
                            ReflectUtils.getInstance().populate(entity, decoded);
                        } catch (RuntimeException e) {
                            throw new EntityEncodingException("Unable to populate bean for ref ("+ref+") from data: " + decoded + ":" + e.getMessage(), ref+"", e);
                        }
                    }
                }
            }
        } else {
View Full Code Here

                        }
                        sb.append(encode);                    
                        encodedEntities++;
                    }
                } catch (RuntimeException e) {
                    throw new EntityEncodingException("Failure during internal output encoding of entity set on entity: " + ref, ref.toString(), e);
                }
            }

            if (!("discover".equals(ref.getPrefix())||"statistics".equals(ref.getPrefix()))) {
                // make footer
                if (Formats.HTML.equals(format)
                        || Formats.FORM.equals(format)) {
                    sb.append("\n<b>Collection size:</b> "+encodedEntities+"\n");
                } else if (Formats.JSON.equals(format)) {
                    sb.append("\n]}");
                } else if (Formats.XML.equals(format)) {
                    sb.append("</"+ ref.getPrefix() + ">");
                } else { // general case
                    sb.append("\nSize: " + encodedEntities + "\n");
                }
            }

            encoded = sb.toString();
        } else {
            // encoding a single entity
            EntityData toEncode = entities.get(0);
            if (toEncode == null) {
                throw new EntityEncodingException("Failed to encode data for entity (" + ref
                        + "), entity object to encode could not be found (null object in list)", ref.toString());
            } else {
                try {
                    String prefix = ref.getPrefix();

                    String segments[] = {};
                    if (params.get("pathInfo") != null) {
                        segments = params.get("pathInfo").toString().split("/");
                    }
                    if (segments.length > 3) {
                        prefix = segments[segments.length - 1].substring(0, segments[segments.length - 1].lastIndexOf("."));
                    }else if (segments[segments.length - 1].startsWith("count")) {
                        prefix = "count";
                    }

                        encoded = encodeEntity(prefix, format, toEncode, view);
                    } catch (RuntimeException e) {
                    throw new EntityEncodingException("Failure during internal output encoding of entity: " + ref, ref.toString(), e);
                }
            }
        }
        // add the HTML headers and footers
        if (Formats.FORM.equals(format)) {
            String title = view.getViewKey() + ":" + ref;
            encoded = XML_HEADER + XHTML_HEADER.replace("{title}", title) + encoded + XHTML_FOOTER;
        } else if (Formats.XML.equals(format)) {
            if (!("discover".equals(ref.getPrefix())||"statistics".equals(ref.getPrefix()))) {
                encoded = XML_HEADER + encoded;
            }
        }
        // put the encoded data into the stream
        try {
            byte[] b = encoded.getBytes(Formats.UTF_8);
            output.write(b);
        } catch (UnsupportedEncodingException e) {
            throw new EntityEncodingException("Failed to encode UTF-8: " + ref, ref.toString(), e);
        } catch (IOException e) {
            throw new EntityEncodingException("Failed to encode into output stream: " + ref, ref.toString(), e);
        }
    }
View Full Code Here

                    if ( (entityData == null
                                || entityData.getData() == null)
                            && (EntityView.VIEW_LIST.equals(viewKey)
                                    || EntityView.VIEW_SHOW.equals(viewKey)) ) {
                        // die if we have no data to encode and this is a SHOW/LIST view
                        throw new EntityEncodingException("Unable to find an entity to encode into the update form; prefix="+prefix+":"+view, prefix);
                    }
                    Object entity = (entityData != null ? entityData.getData() : null);
                    if (entity == null) {
                        // get the entity from the URL instead
                        String id = (view.getEntityReference() != null ? view.getEntityReference().getId() : null);
                        if (id == null) {
                            id = (entityData != null ? entityData.getEntityId() : null);
                        }
                        entity = entityBrokerManager.getSampleEntityObject(prefix, id);
                        if (entity == null) {
                            throw new EntityEncodingException("Unable to find entity data to create form from using prefix="+prefix+",id="+id, prefix);
                        }
                    }
                    Class<?> entityClass = entity.getClass();
                    String formAction;
                    if (EntityView.VIEW_NEW.equals(viewKey)) {
View Full Code Here

TOP

Related Classes of org.sakaiproject.entitybus.exception.EntityEncodingException

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.