| 825 | | String strEntityType; |
| 826 | | String strEntityID = null; |
| 827 | | String strAttrID; |
| 828 | | Element attributeElement; |
| 829 | | Element attributeValueElement; |
| 830 | | Element simpleDataElement; |
| 831 | | IEntity entity = null; |
| 832 | | |
| 833 | | // Root element must be an Entity element |
| 834 | | |
| 835 | | if (!DomFuncs.isElementNode( entityElement, RESTConstants.IDAS_REST_NAMESPACE, RESTConstants.REST_ENTITY_ELEMENT)) |
| 836 | | { |
| 837 | | throwException( new OtisErrMsg( "EntityHandler(adding entity", |
| 838 | | OtisErrMsg.OPTIONAL_STR( ", session='" + strSessionID + "'"), |
| 839 | | "): Request body has no " + RESTConstants.REST_ENTITY_ELEMENT + " element"), |
| 840 | | null, HttpServletResponse.SC_BAD_REQUEST, responseMap); |
| 841 | | } |
| 842 | | |
| 843 | | // Entity element must have an entityType attribute |
| 844 | | |
| 845 | | if ((strEntityType = entityElement.getAttribute( RESTConstants.REST_ENTITY_TYPE_ATTR)) == null) |
| 846 | | { |
| 847 | | throwException( new OtisErrMsg( "EntityHandler(adding entity", |
| 848 | | OtisErrMsg.OPTIONAL_STR( ", session='" + strSessionID + "'"), |
| 849 | | "): Entity element has no " + RESTConstants.REST_ENTITY_TYPE_ATTR + " attribute"), |
| 850 | | null, HttpServletResponse.SC_BAD_REQUEST, responseMap); |
| 851 | | } |
| 852 | | |
| 853 | | // Loop through all of the attributes - find the one containing the entity ID. |
| 854 | | |
| 855 | | attributeElement = DomFuncs.getFirstChildElement( entityElement, RESTConstants.IDAS_REST_NAMESPACE, RESTConstants.REST_ATTRIBUTE_ELEMENT); |
| 856 | | while (attributeElement != null) |
| 857 | | { |
| 858 | | if ((strAttrID = attributeElement.getAttribute( RESTConstants.REST_ATTR_ID_ATTR)) == null) |
| | 825 | try |
| | 826 | { |
| | 827 | String strEntityType; |
| | 828 | String strEntityID = null; |
| | 829 | String strAttrID; |
| | 830 | Element attributeElement; |
| | 831 | Element attributeValueElement; |
| | 832 | Element simpleDataElement; |
| | 833 | IEntity entity = null; |
| | 834 | |
| | 835 | // Root element must be an Entity element |
| | 836 | |
| | 837 | if (!DomFuncs.isElementNode( entityElement, RESTConstants.IDAS_REST_NAMESPACE, RESTConstants.REST_ENTITY_ELEMENT)) |
| 865 | | if (strAttrID.equals( ITypedValue.ENTITYID_ATTR_VALUE_TYPE_URI_STR)) |
| 866 | | { |
| 867 | | // There better be a single AttributeValue element with a simple Data element. |
| 868 | | |
| 869 | | if ((attributeValueElement = DomFuncs.getFirstChildElement( attributeElement, |
| 870 | | RESTConstants.IDAS_REST_NAMESPACE, RESTConstants.REST_ATTRIBUTE_VALUE_ELEMENT)) == null) |
| | 844 | |
| | 845 | // Entity element must have an entityType attribute |
| | 846 | |
| | 847 | if ((strEntityType = entityElement.getAttribute( RESTConstants.REST_ENTITY_TYPE_ATTR)) == null) |
| | 848 | { |
| | 849 | throwException( new OtisErrMsg( "EntityHandler(adding entity", |
| | 850 | OtisErrMsg.OPTIONAL_STR( ", session='" + strSessionID + "'"), |
| | 851 | "): Entity element has no " + RESTConstants.REST_ENTITY_TYPE_ATTR + " attribute"), |
| | 852 | null, HttpServletResponse.SC_BAD_REQUEST, responseMap); |
| | 853 | } |
| | 854 | |
| | 855 | // Loop through all of the attributes - find the one containing the entity ID. |
| | 856 | |
| | 857 | attributeElement = DomFuncs.getFirstChildElement( entityElement, RESTConstants.IDAS_REST_NAMESPACE, RESTConstants.REST_ATTRIBUTE_ELEMENT); |
| | 858 | while (attributeElement != null) |
| | 859 | { |
| | 860 | if ((strAttrID = attributeElement.getAttribute( RESTConstants.REST_ATTR_ID_ATTR)) == null) |
| | 867 | if (strAttrID.equals( ITypedValue.ENTITYID_ATTR_VALUE_TYPE_URI_STR)) |
| | 868 | { |
| | 869 | // There better be a single AttributeValue element with a simple Data element. |
| | 870 | |
| | 871 | if ((attributeValueElement = DomFuncs.getFirstChildElement( attributeElement, |
| | 872 | RESTConstants.IDAS_REST_NAMESPACE, RESTConstants.REST_ATTRIBUTE_VALUE_ELEMENT)) == null) |
| | 873 | { |
| | 874 | throwException( new OtisErrMsg( "EntityHandler(adding entity", |
| | 875 | OtisErrMsg.OPTIONAL_STR( ", session='" + strSessionID + "'"), |
| | 876 | "): Attribute element containing the entity ID has no " + RESTConstants.REST_ATTRIBUTE_VALUE_ELEMENT + " element"), |
| | 877 | null, HttpServletResponse.SC_BAD_REQUEST, responseMap); |
| | 878 | } |
| | 879 | |
| | 880 | // Make sure there are no other attribute value elements |
| | 881 | |
| | 882 | if (DomFuncs.getNextSiblingElement( attributeValueElement, RESTConstants.IDAS_REST_NAMESPACE, RESTConstants.REST_ATTRIBUTE_VALUE_ELEMENT) != null) |
| | 883 | { |
| | 884 | throwException( new OtisErrMsg( "EntityHandler(adding entity", |
| | 885 | OtisErrMsg.OPTIONAL_STR( ", session='" + strSessionID + "'"), |
| | 886 | "): Attribute element containing the entity ID has multiple " + RESTConstants.REST_ATTRIBUTE_VALUE_ELEMENT + |
| | 887 | " elements, entity ID attribute must be single-valued"), |
| | 888 | null, HttpServletResponse.SC_BAD_REQUEST, responseMap); |
| | 889 | } |
| | 890 | |
| | 891 | // Better be a data element |
| | 892 | |
| | 893 | if ((simpleDataElement = DomFuncs.getFirstChildElement( attributeValueElement, |
| | 894 | RESTConstants.IDAS_REST_NAMESPACE, RESTConstants.REST_SIMPLE_DATA_ELEMENT)) == null) |
| | 895 | { |
| | 896 | throwException( new OtisErrMsg( "EntityHandler(adding entity", |
| | 897 | OtisErrMsg.OPTIONAL_STR( ", session='" + strSessionID + "'"), |
| | 898 | "): AttributeValue element containing the entity ID has no " + |
| | 899 | RESTConstants.REST_SIMPLE_DATA_ELEMENT + " element"), |
| | 900 | null, HttpServletResponse.SC_BAD_REQUEST, responseMap); |
| | 901 | } |
| | 902 | strEntityID = DomFuncs.getNodeText( simpleDataElement); |
| | 903 | if (strEntityID.trim().equals( "")) |
| | 904 | { |
| | 905 | throwException( new OtisErrMsg( "EntityHandler(adding entity", |
| | 906 | OtisErrMsg.OPTIONAL_STR( ", session='" + strSessionID + "'"), |
| | 907 | "): AttributeValue element containing the entity ID has empty value"), |
| | 908 | null, HttpServletResponse.SC_BAD_REQUEST, responseMap); |
| | 909 | } |
| | 910 | break; |
| | 911 | } |
| 880 | | if (DomFuncs.getNextSiblingElement( attributeValueElement, RESTConstants.IDAS_REST_NAMESPACE, RESTConstants.REST_ATTRIBUTE_VALUE_ELEMENT) != null) |
| 881 | | { |
| 882 | | throwException( new OtisErrMsg( "EntityHandler(adding entity", |
| 883 | | OtisErrMsg.OPTIONAL_STR( ", session='" + strSessionID + "'"), |
| 884 | | "): Attribute element containing the entity ID has multiple " + RESTConstants.REST_ATTRIBUTE_VALUE_ELEMENT + |
| 885 | | " elements, entity ID attribute must be single-valued"), |
| 886 | | null, HttpServletResponse.SC_BAD_REQUEST, responseMap); |
| 887 | | } |
| 888 | | |
| 889 | | // Better be a data element |
| 890 | | |
| 891 | | if ((simpleDataElement = DomFuncs.getFirstChildElement( attributeValueElement, |
| 892 | | RESTConstants.IDAS_REST_NAMESPACE, RESTConstants.REST_SIMPLE_DATA_ELEMENT)) == null) |
| 893 | | { |
| 894 | | throwException( new OtisErrMsg( "EntityHandler(adding entity", |
| 895 | | OtisErrMsg.OPTIONAL_STR( ", session='" + strSessionID + "'"), |
| 896 | | "): AttributeValue element containing the entity ID has no " + |
| 897 | | RESTConstants.REST_SIMPLE_DATA_ELEMENT + " element"), |
| 898 | | null, HttpServletResponse.SC_BAD_REQUEST, responseMap); |
| 899 | | } |
| 900 | | strEntityID = DomFuncs.getNodeText( simpleDataElement); |
| 901 | | if (strEntityID.trim().equals( "")) |
| 902 | | { |
| 903 | | throwException( new OtisErrMsg( "EntityHandler(adding entity", |
| 904 | | OtisErrMsg.OPTIONAL_STR( ", session='" + strSessionID + "'"), |
| 905 | | "): AttributeValue element containing the entity ID has empty value"), |
| 906 | | null, HttpServletResponse.SC_BAD_REQUEST, responseMap); |
| 907 | | } |
| 908 | | break; |
| 909 | | } |
| 910 | | |
| 911 | | // Go to the next attribute element. |
| 912 | | |
| 913 | | attributeElement = DomFuncs.getNextSiblingElement( attributeElement, RESTConstants.IDAS_REST_NAMESPACE, RESTConstants.REST_ATTRIBUTE_ELEMENT); |
| 914 | | } |
| 915 | | |
| 916 | | if (strEntityID == null) |
| 917 | | { |
| 918 | | throwException( new OtisErrMsg( "EntityHandler(adding entity", |
| 919 | | OtisErrMsg.OPTIONAL_STR( ", session='" + strSessionID + "'"), |
| 920 | | "): No '" + ITypedValue.ENTITYID_ATTR_VALUE_TYPE_URI_STR + "' attribute specified for " + |
| 921 | | "the entity being added, cannot determine entity ID without it"), |
| 922 | | null, HttpServletResponse.SC_BAD_REQUEST, responseMap); |
| 923 | | } |
| 924 | | |
| 925 | | // We can now create the entity object, as we have an entity type and entity ID. |
| 926 | | |
| 927 | | try |
| 928 | | { |
| 929 | | entity = localAuthSession.addEntity( new URI( strEntityType), strEntityID); |
| 930 | | } |
| 931 | | catch (URISyntaxException e) |
| 932 | | { |
| 933 | | throwException( new OtisErrMsg( "EntityHandler", |
| 934 | | OtisErrMsg.OPTIONAL_STR( "(session='" + strSessionID + "', Entity='" + strEntityID + "')"), |
| 935 | | ": Entity type ", |
| 936 | | OtisErrMsg.OPTIONAL_STR( "'" + strEntityType + "' "), |
| 937 | | "is not a valid URI"), |
| 938 | | e, HttpServletResponse.SC_BAD_REQUEST, responseMap); |
| 939 | | } |
| 940 | | catch (IdASException e) |
| 941 | | { |
| 942 | | throwException( new OtisErrMsg( "EntityHandler", |
| 943 | | OtisErrMsg.OPTIONAL_STR( "(session='" + strSessionID + "', Entity='" + strEntityID + "')"), |
| 944 | | ": Exception " + e.getClass().getName() + " occurred while creating entity", |
| 945 | | OtisErrMsg.OPTIONAL_STR( ": " + e.getMessage())), |
| 946 | | e, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, responseMap); |
| 947 | | } |
| 948 | | |
| 949 | | // Go through all of the child elements and process them. They better all be |
| 950 | | // attribute elements at this point. |
| 951 | | |
| 952 | | Node childNode = entityElement.getFirstChild(); |
| 953 | | while (childNode != null) |
| 954 | | { |
| 955 | | if (childNode.getNodeType() == Node.ELEMENT_NODE) |
| 956 | | { |
| 957 | | String strNodeElementName = childNode.getLocalName(); |
| 958 | | String strNodeNamespace = childNode.getNamespaceURI(); |
| 959 | | |
| 960 | | if (!strNodeNamespace.equals( RESTConstants.IDAS_REST_NAMESPACE)) |
| 961 | | { |
| 962 | | throwException( new OtisErrMsg( "EntityHandler", |
| | 915 | attributeElement = DomFuncs.getNextSiblingElement( attributeElement, RESTConstants.IDAS_REST_NAMESPACE, RESTConstants.REST_ATTRIBUTE_ELEMENT); |
| | 916 | } |
| | 917 | |
| | 918 | if (strEntityID == null) |
| | 919 | { |
| | 920 | throwException( new OtisErrMsg( "EntityHandler(adding entity", |
| | 921 | OtisErrMsg.OPTIONAL_STR( ", session='" + strSessionID + "'"), |
| | 922 | "): No '" + ITypedValue.ENTITYID_ATTR_VALUE_TYPE_URI_STR + "' attribute specified for " + |
| | 923 | "the entity being added, cannot determine entity ID without it"), |
| | 924 | null, HttpServletResponse.SC_BAD_REQUEST, responseMap); |
| | 925 | } |
| | 926 | |
| | 927 | // We can now create the entity object, as we have an entity type and entity ID. |
| | 928 | |
| | 929 | try |
| | 930 | { |
| | 931 | entity = localAuthSession.addEntity( new URI( strEntityType), strEntityID); |
| | 932 | } |
| | 933 | catch (URISyntaxException e) |
| | 934 | { |
| | 935 | throwException( new OtisErrMsg( "EntityHandler", |
| | 950 | |
| | 951 | // Go through all of the child elements and process them. They better all be |
| | 952 | // attribute elements at this point. |
| | 953 | |
| | 954 | Node childNode = entityElement.getFirstChild(); |
| | 955 | while (childNode != null) |
| | 956 | { |
| | 957 | if (childNode.getNodeType() == Node.ELEMENT_NODE) |
| | 958 | { |
| | 959 | String strNodeElementName = childNode.getLocalName(); |
| | 960 | String strNodeNamespace = childNode.getNamespaceURI(); |
| | 961 | |
| | 962 | if (!strNodeNamespace.equals( RESTConstants.IDAS_REST_NAMESPACE)) |
| | 963 | { |
| | 964 | throwException( new OtisErrMsg( "EntityHandler", |
| | 965 | OtisErrMsg.OPTIONAL_STR( "(session='" + strSessionID + "', Entity='" + strEntityID + "')"), |
| | 966 | ": Unexpected element ", |
| | 967 | OtisErrMsg.OPTIONAL_STR( strNodeElementName + " (namespace='" + strNodeNamespace + "') "), |
| | 968 | "found as child element of the " + RESTConstants.REST_ENTITY_ELEMENT + " element"), |
| | 969 | null, HttpServletResponse.SC_BAD_REQUEST, responseMap); |
| | 970 | } |
| | 971 | if (strNodeElementName.equals( RESTConstants.REST_ATTRIBUTE_ELEMENT)) |
| | 972 | { |
| | 973 | this.addAttribute( strSessionID, "Entity='" + strEntityID, entity, (Element)childNode, false, responseMap); |
| | 974 | } |
| | 975 | else |
| | 976 | { |
| | 977 | throwException( new OtisErrMsg( "EntityHandler", |
| | 978 | OtisErrMsg.OPTIONAL_STR( "(session='" + strSessionID + "', Entity='" + strEntityID + "')"), |
| | 979 | ": Unexpected element ", |
| | 980 | OtisErrMsg.OPTIONAL_STR( strNodeElementName + " (namespace='" + strNodeNamespace + "') "), |
| | 981 | "found as child element of the " + RESTConstants.REST_ENTITY_ELEMENT + " element"), |
| | 982 | null, HttpServletResponse.SC_BAD_REQUEST, responseMap); |
| | 983 | } |
| | 984 | } |
| | 985 | childNode = childNode.getNextSibling(); |
| | 986 | } |
| | 987 | |
| | 988 | // Call apply updates |
| | 989 | |
| | 990 | if (bApplyUpdates) |
| | 991 | { |
| | 992 | try |
| | 993 | { |
| | 994 | localAuthSession.applyUpdates(); |
| | 995 | } |
| | 996 | catch (IdASException e) |
| | 997 | { |
| | 998 | throwException( new OtisErrMsg( "EntityHandler", |
| | 999 | OtisErrMsg.OPTIONAL_STR( "(Entity='" + strEntityID + "', session='" + strSessionID + "')"), |
| | 1000 | ": Exception " + e.getClass().getName() + " occurred calling applyUpdates", |
| | 1001 | OtisErrMsg.OPTIONAL_STR( ": " + e.getMessage())), |
| | 1002 | e, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, responseMap); |
| | 1003 | } |
| | 1004 | } |
| | 1005 | } |
| | 1006 | catch (OtisException e) |
| | 1007 | { |
| | 1008 | if (bApplyUpdates) |
| | 1009 | { |
| | 1010 | try |
| | 1011 | { |
| | 1012 | localAuthSession.cancelUpdates(); |
| | 1013 | } |
| | 1014 | catch (IdASException e2) |
| | 1015 | { |
| | 1016 | } |
| | 1017 | } |
| | 1018 | throw e; |
| 1452 | | attrContainer.removeAttribute( new URI( strAttrID)); |
| 1453 | | } |
| 1454 | | catch (URISyntaxException e) |
| 1455 | | { |
| 1456 | | throwException( new OtisErrMsg( "EntityHandler", |
| 1457 | | OtisErrMsg.OPTIONAL_STR( "(session='" + strSessionID + "', " + strAttrContainer + ")"), |
| 1458 | | ": URISyntaxException parsing attribute URI", |
| 1459 | | OtisErrMsg.OPTIONAL_STR( " '" + strAttrID + "': " + e.getMessage())), |
| 1460 | | null, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, responseMap); |
| 1461 | | } |
| 1462 | | catch (IdASException e) |
| 1463 | | { |
| 1464 | | throwException( new OtisErrMsg( "EntityHandler", |
| 1465 | | OtisErrMsg.OPTIONAL_STR( "(session='" + strSessionID + "', " + strAttrContainer + ")"), |
| 1466 | | ": Exception " + e.getClass().getName() + " occurred while removing attribute", |
| 1467 | | OtisErrMsg.OPTIONAL_STR( " '" + strAttrID + "': " + e.getMessage())), |
| 1468 | | e, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, responseMap); |
| 1469 | | } |
| 1470 | | |
| 1471 | | if (localAuthSession != null) |
| 1472 | | { |
| | 1468 | validateAttrID( strSessionID, strAttrContainer, strAttrID, "remove", null, responseMap); |