@ -21,10 +21,9 @@ import de.srsoftware.umbrella.core.ModuleRegistry;
				@@ -21,10 +21,9 @@ import de.srsoftware.umbrella.core.ModuleRegistry;
					 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					import  de.srsoftware.umbrella.core.api.StockService ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					import  de.srsoftware.umbrella.core.exceptions.UmbrellaException ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					import  de.srsoftware.umbrella.core.model.* ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					import  org.json.JSONObject ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					import  java.io.IOException ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					import  java.util.* ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					import  org.json.JSONObject ;  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					public  class  StockModule  extends  BaseHandler  implements  StockService  {  
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					
 
				
			 
			
		
	
	
		
			
				
					
						
							
								 
							 
						
						
							
								 
							 
						
						
					 
				
				 
				 
				
					@ -133,31 +132,32 @@ public class StockModule extends BaseHandler implements StockService {
				@@ -133,31 +132,32 @@ public class StockModule extends BaseHandler implements StockService {
					 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
						private  boolean  postProperty ( UmbrellaUser  user ,  HttpExchange  ex )  throws  IOException  {   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
							var  json  =  json ( ex ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
							if  ( ! ( json . get ( ID )  instanceof  Number  id ) )  throw  missingFieldException ( ID ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
							if  ( ! ( json . get ( FIELD_ITEM )  instanceof  JSONObject  itemData ) )  throw  missingFieldException ( FIELD_ITEM ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
							if  ( ! ( itemData . get ( OWNER )  instanceof  JSONObject  owner ) )  throw  missingFieldException ( OWNER ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
							if  ( ! ( itemData . get ( ID )  instanceof  Number  itemId ) )  throw  missingFieldException ( ID ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
							if  ( ! ( json . get ( "add_prop" )  instanceof  JSONObject  propData ) )  throw  missingFieldException ( "add_prop" ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
							if  ( ! propData . has ( VALUE ) )  throw  missingFieldException ( VALUE ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
							var  value  =  propData . get ( VALUE ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
							if  ( value  = =  null )  throw  missingFieldException ( VALUE ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
							var  keys  =  owner . keySet ( ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
							if  ( keys . size ( )  ! =  1 )  throw  unprocessable ( "{0} expected to have only one child!" , OWNER ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
							var   key  =  new  ArrayList < > ( keys ) . getFirst ( ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
							var   ownerId  =  switch  ( key )  {   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
								case  COMPANY  - >  - js on. getLong ( key ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
								case  USER  - >  js on. getLong ( key ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
								case  null ,  default  - >  throw  invalidFieldException ( format ( "Single child of {0}" ,  OWNER ) ,  format ( "either {0} or {1}" ,  COMPANY ,  USER ) ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
							String   key  =  new  ArrayList < > ( keys ) . getFirst ( ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
							long   ownerId  =  switch  ( key )  {   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
								case  COMPANY  - >  - ow ner  . getLong ( key ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
								case  USER  - >  ow ner  . getLong ( key ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
								default  - >  throw  invalidFieldException ( format ( "Single child of {0}" ,  OWNER ) ,  format ( "either {0} or {1}" ,  COMPANY ,  USER ) ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
							} ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
							Property  property  =  null ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
							if  ( propData . get ( "existing_prop_id" )  instanceof  Number  existingPropId  & &  existingPropId . longValue ( )  ! =  0L ) {   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
								stockDb . addProperty ( ownerId , id . longValue ( ) , existingPropId . longValue ( ) , value ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
								property  =  stockDb . addProperty ( ownerId , itemI d . longValue ( ) , existingPropId . longValue ( ) , value ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
							}  else  {   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
								if  ( ! ( propData . get ( "new_prop" )  instanceof  JSONObject  newProp ) )  throw  unprocessable ( "data must contain either add_prop.existing_prop_id or add_prop.new_prop!" ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
								if  ( ! ( newProp . get ( NAME )  instanceof  String  name )  | |  name . isBlank ( ) )  throw  unprocessable ( "data.add_prop.new_prop does not contain name!" ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
								var  unit  =  newProp . get ( UNIT )  instanceof  String  u  ?  nullIfEmpty ( u )  :  null ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
								stockDb . addProperty ( ownerId , id . longValue ( ) , name , value , unit ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
								property  =  stockDb . addNew Property ( ownerId , itemI d . longValue ( ) , name , value , unit ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
							}   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
							return  sendEmptyResponse ( 500 , ex  ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
							return  sendContent ( ex , property  ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
						}   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
						@Override