@Override public <T extends IdentifiableObject> void clearSharing( T object, User user ) { if ( object == null || !isShareable( object.getClass() ) || user == null ) { return; } BaseIdentifiableObject baseIdentifiableObject = (BaseIdentifiableObject) object; baseIdentifiableObject.setUser( user ); baseIdentifiableObject.setPublicAccess( AccessStringHelper.DEFAULT ); baseIdentifiableObject.setExternalAccess( false ); object.getUserAccesses().clear(); object.getUserGroupAccesses().clear(); }
public BaseIdentifiableObject( IdentifiableObject identifiableObject ) { this.id = identifiableObject.getId(); this.uid = identifiableObject.getUid(); this.name = identifiableObject.getName(); this.created = identifiableObject.getCreated(); this.lastUpdated = identifiableObject.getLastUpdated(); }
if ( identifiableObject.getDisplayName() != null && !identifiableObject.getDisplayName().isEmpty() ) return identifiableObject.getDisplayName(); else if ( identifiableObject.getUid() != null && !identifiableObject.getUid().isEmpty() ) return identifiableObject.getUid(); else if ( identifiableObject.getCode() != null && !identifiableObject.getCode().isEmpty() ) return identifiableObject.getCode();
/** * Returns a list of uids for the given collection of IdentifiableObjects. * * @param objects the list of IdentifiableObjects. * @return a list of uids. */ public static <T extends IdentifiableObject> List<String> getUids( Collection<T> objects ) { return objects != null ? objects.stream().map( o -> o.getUid() ).collect( Collectors.toList() ) : null; }
public static String getValue( IdentifiableObject identifiableObject, IdScheme idScheme ) { boolean isId = idScheme.is( IdentifiableProperty.ID ) || idScheme.is( IdentifiableProperty.UID ); if ( isId ) { return identifiableObject.getUid(); } else if ( idScheme.is( IdentifiableProperty.CODE ) ) { return identifiableObject.getCode(); } else if ( idScheme.is( IdentifiableProperty.NAME ) ) { return identifiableObject.getName(); } return null; }
object.getAttributeValues().stream() .filter( attributeValue -> attributeValue.getAttribute() != null && preheat.get( identifier, attributeValue.getAttribute() ) == null ) .forEach( attributeValue -> preheatErrorReports.add( new PreheatErrorReport( identifier, object.getClass(), ErrorCode.E5002, object.getUserGroupAccesses().stream() .filter( userGroupAccess -> !skipSharing && userGroupAccess.getUserGroup() != null && preheat.get( identifier, userGroupAccess.getUserGroup() ) == null ) .forEach( userGroupAccesses -> preheatErrorReports.add( new PreheatErrorReport( identifier, object.getClass(), ErrorCode.E5002, object.getUserAccesses().stream() .filter( userGroupAccess -> !skipSharing && userGroupAccess.getUser() != null && preheat.get( identifier, userGroupAccess.getUser() ) == null ) .forEach( userAccesses -> preheatErrorReports.add( new PreheatErrorReport( identifier, object.getClass(), ErrorCode.E5002,
private TypeReport validateForCreate( Class<? extends IdentifiableObject> klass, List<IdentifiableObject> objects, ObjectBundle bundle ) { TypeReport typeReport = new TypeReport( klass ); if ( objects == null || objects.isEmpty() ) { return typeReport; } Iterator<IdentifiableObject> iterator = objects.iterator(); int idx = 0; while ( iterator.hasNext() ) { IdentifiableObject identifiableObject = iterator.next(); IdentifiableObject object = bundle.getPreheat().get( bundle.getPreheatIdentifier(), identifiableObject ); if ( object != null && object.getId() > 0 ) { ObjectReport objectReport = new ObjectReport( klass, idx, object.getUid() ); objectReport.setDisplayName( IdentifiableObjectUtils.getDisplayName( object ) ); objectReport.addErrorReport( new ErrorReport( klass, ErrorCode.E5000, bundle.getPreheatIdentifier(), bundle.getPreheatIdentifier().getIdentifiersWithName( identifiableObject ) ).setMainId( identifiableObject.getUid() ) ); typeReport.addObjectReport( objectReport ); typeReport.getStats().incIgnored(); iterator.remove(); } idx++; } return typeReport; }
if ( !AccessStringHelper.isValid( object.getPublicAccess() ) ) errorReports.add( new ErrorReport( object.getClass(), ErrorCode.E3010, object.getPublicAccess() ) ); return errorReports; if ( object.getPublicAccess() != null && AccessStringHelper.hasDataSharing( object.getPublicAccess() ) ) for ( UserAccess userAccess : object.getUserAccesses() ) for ( UserGroupAccess userGroupAccess : object.getUserGroupAccesses() ) boolean canMakeExternal = canMakeExternal( user, object.getClass() ); if ( object.getExternalAccess() ) if ( AccessStringHelper.DEFAULT.equals( object.getPublicAccess() ) )
private void handleUniqueAttributeValues( Class<? extends IdentifiableObject> klass, List<? extends IdentifiableObject> objects, Preheat preheat ) { if ( objects.isEmpty() ) { return; } preheat.getUniqueAttributeValues().put( klass, new HashMap<>() ); objects.forEach( object -> { object.getAttributeValues().forEach( attributeValue -> { Set<String> uids = preheat.getUniqueAttributes().get( klass ); if ( uids != null && uids.contains( attributeValue.getAttribute().getUid() ) ) { if ( !preheat.getUniqueAttributeValues().get( klass ).containsKey( attributeValue.getAttribute().getUid() ) ) { preheat.getUniqueAttributeValues().get( klass ).put( attributeValue.getAttribute().getUid(), new HashMap<>() ); } preheat.getUniqueAttributeValues().get( klass ).get( attributeValue.getAttribute().getUid() ) .put( attributeValue.getValue(), object.getUid() ); } } ); } ); }
if ( AccessStringHelper.isEnabled( object.getPublicAccess(), permission ) ) for ( UserGroupAccess userGroupAccess : object.getUserGroupAccesses() ) for ( UserAccess userAccess : object.getUserAccesses() )
@Override public <T extends IdentifiableObject> void resetSharing( T object, User user ) { if ( object == null || !isShareable( object.getClass() ) || user == null ) { return; } BaseIdentifiableObject baseIdentifiableObject = (BaseIdentifiableObject) object; baseIdentifiableObject.setPublicAccess( AccessStringHelper.DEFAULT ); baseIdentifiableObject.setExternalAccess( false ); if ( object.getUser() == null ) { baseIdentifiableObject.setUser( user ); } if ( canMakePublic( user, object.getClass() ) ) { if ( defaultPublic( object.getClass() ) ) { baseIdentifiableObject.setPublicAccess( AccessStringHelper.READ_WRITE ); } } object.getUserAccesses().clear(); object.getUserGroupAccesses().clear(); }
@Override public <P extends IdentifiableObject> boolean isAttributeValueUnique( P object, Attribute attribute, String value ) { List<AttributeValue> values = getAttributeValueByAttributeAndValue( attribute, value ); return values.isEmpty() || (object != null && values.size() == 1 && object.getAttributeValues().contains( values.get( 0 ) )); }
private void clearDefaults( Class<?> klass, List<? extends IdentifiableObject> objects, Defaults defaults ) { if ( Defaults.INCLUDE == defaults || !Preheat.isDefaultClass( klass ) ) { return; } objects.removeIf( object -> "default".equals( object.getName() ) ); } }
/** * Returns a mapping between the uid and the property defined by the given * identifiable property for the given identifiable objects. * * @param objects the identifiable objects. * @param property the identifiable property. * @return a mapping between uid and property. */ public static Map<String, String> getUidPropertyMap( Collection<? extends IdentifiableObject> objects, IdentifiableProperty property ) { Map<String, String> map = Maps.newHashMap(); objects.forEach( obj -> map.put( obj.getUid(), obj.getPropertyValue( IdScheme.from( property ) ) ) ); return map; }
protected void enableDataSharing( User user, IdentifiableObject object, String access ) { object.getUserAccesses().clear(); UserAccess userAccess = new UserAccess(); userAccess.setUser( user ); userAccess.setAccess( access ); object.getUserAccesses().add( userAccess ); } }
public static <T extends IdentifiableObject> int getCountByName( Collection<T> objects, String name ) { int count = 0; if ( name != null ) { for ( IdentifiableObject object : objects ) { if ( object != null && object.getDisplayName() != null && object.getDisplayName().toLowerCase().contains( name.toLowerCase() ) ) { count++; } } } return count; }
/** * Returns a list of internal identifiers for the given collection of IdentifiableObjects. * * @param objects the list of IdentifiableObjects. * @return a list of identifiers. */ public static <T extends IdentifiableObject> List<Integer> getIdentifiers( Collection<T> objects ) { return objects != null ? objects.stream().map( o -> o.getId() ).collect( Collectors.toList() ) : null; }