public static Response getOverwriteResponse ( App app , String id , String type , InputStream is ) { try ( final Metrics . Context context = Metrics . time ( app == null ? null : app . getAppid ( ) , RestUtils . class , "crud" , "overwrite" ) ) { ParaObject content ; Response entityRes = getEntity ( is , Map . class ) ; if ( entityRes . getStatusInfo ( ) == Response . Status . OK ) { Map < String , Object > newContent = ( Map < String , Object > ) entityRes . getEntity ( ) ; if ( ! StringUtils . isBlank ( type ) ) { newContent . put ( Config . _TYPE , type ) ; } content = ParaObjectUtils . setAnnotatedFields ( newContent ) ; if ( app != null && content != null && ! StringUtils . isBlank ( id ) && isNotAnApp ( type ) ) { warnIfUserTypeDetected ( type ) ; content . setType ( type ) ; content . setAppid ( app . getAppIdentifier ( ) ) ; content . setId ( id ) ; setCreatorid ( app , content ) ; int typesCount = app . getDatatypes ( ) . size ( ) ; app . addDatatypes ( content ) ; // The reason why we do two validation passes is because we want to return // the errors through the API and notify the end user. // This is the primary validation pass (validates not only core POJOS but also user defined objects). String [ ] errors = validateObject ( app , content ) ; if ( errors . length == 0 && checkIfUserCanModifyObject ( app , content ) ) { // Secondary validation pass called here. Object is validated again before being created // See: IndexAndCacheAspect.java CoreUtils . getInstance ( ) . overwrite ( app . getAppIdentifier ( ) , content ) ; // new type added so update app object if ( typesCount < app . getDatatypes ( ) . size ( ) ) { app . update ( ) ; } return Response . ok ( content ) . build ( ) ; } return getStatusResponse ( Response . Status . BAD_REQUEST , errors ) ; } return getStatusResponse ( Response . Status . BAD_REQUEST , "Failed to overwrite object." ) ; } return entityRes ; } }
Overwrite response as JSON .