/** @throws FacebookException if the GraphObject doesn't have an ID. */ String getIdOfGraphObject(T graphObject) { if (graphObject.asMap().containsKey(ID)) { Object obj = graphObject.getProperty(ID); if (obj instanceof String) { return (String) obj; } } throw new FacebookException("Received an object without an ID."); }
protected String getSectionKeyOfGraphObject(T graphObject) { String result = null; if (groupByField != null) { result = (String) graphObject.getProperty(groupByField); if (result != null && result.length() > 0) { result = result.substring(0, 1).toUpperCase(); } } return (result != null) ? result : ""; }
@Override public Object getColumnValue(T baseObject, int column) { switch (column) { case PLAY_INDEX: return baseObject; case NUMBER_INDEX: return (baseObject instanceof PlaylistFileItem) ? ((PlaylistFileItem) baseObject).getIndex() : null; case TITLE_INDEX: return baseObject; case ARTIST_INDEX: return baseObject.getProperty(FilePropertyKey.AUTHOR); case ALBUM_INDEX: return baseObject.getProperty(FilePropertyKey.ALBUM); case LENGTH_INDEX: return baseObject.getProperty(FilePropertyKey.LENGTH); case GENRE_INDEX: return baseObject.getProperty(FilePropertyKey.GENRE); case BITRATE_INDEX: return baseObject.getProperty(FilePropertyKey.BITRATE); case SIZE_INDEX: return baseObject.getSize(); case FILENAME_INDEX: return baseObject.getFileName(); case TRACK_INDEX: return baseObject.getProperty(FilePropertyKey.TRACK_NUMBER); case YEAR_INDEX: return baseObject.getProperty(FilePropertyKey.YEAR); case QUALITY_INDEX: return baseObject; case DESCRIPTION_INDEX: return baseObject.getProperty(FilePropertyKey.DESCRIPTION); case HIT_INDEX: return baseObject.getNumHits(); case UPLOADS_INDEX: return baseObject.getNumUploads(); case UPLOAD_ATTEMPTS_INDEX: return baseObject.getNumUploadAttempts(); case PATH_INDEX: return baseObject.getProperty(FilePropertyKey.LOCATION); } throw new IllegalArgumentException("Unknown column:" + column); }
/** * Create a mock CmisObject using Mockito that will contain the provided properties * * @param properties Array of arrays in the form of {{propertyId, displayName, propertyValue}} * @param clazz Class object in the CmisObject hierarchy that has to be created * @return The mocked CmisObject */ protected <T extends CmisObject> T createMockedCmisObject(Object[][] properties, Class<T> clazz) { T object = mock(clazz); List<Property<?>> documentProperties = new ArrayList<Property<?>>(); for (Object[] mockProp : properties) { Property prop = createMockedProperty(mockProp[0], mockProp[1], mockProp[2]); documentProperties.add(prop); when(object.getProperty(mockProp[0].toString())).thenReturn(prop); if (PropertyIds.NAME.equals(mockProp[0])) { when(object.getName()).thenReturn(mockProp[2].toString()); } } when(object.getProperties()).thenReturn(documentProperties); return object; }
protected URI getPictureUriOfGraphObject(T graphObject) { String uri = null; Object o = graphObject.getProperty(PICTURE); if (o instanceof String) { uri = (String) o; } else if (o instanceof JSONObject) { ItemPicture itemPicture = GraphObject.Factory.create((JSONObject) o).cast(ItemPicture.class); ItemPictureData data = itemPicture.getData(); if (data != null) { uri = data.getUrl(); } } if (uri != null) { try { return new URI(uri); } catch (URISyntaxException e) { } } return null; }
@Override public T instantiateWithType( final Relationship relationship, final Class<T> relClass, final boolean isCreation) throws FrameworkException { logger.log(Level.FINEST, "Instantiate relationship with type {0}", relClass.getName()); SecurityContext securityContext = factoryProfile.getSecurityContext(); T newRel = null; try { newRel = relClass.newInstance(); } catch (Throwable t) { newRel = null; } if (newRel == null) { newRel = (T) StructrApp.getConfiguration().getFactoryDefinition().createGenericRelationship(); } newRel.init(securityContext, relationship); // try to set correct type property on relationship entity final String type = newRel.getProperty(GraphObject.type); if (type == null || (type != null && !type.equals(relClass.getSimpleName()))) { newRel.unlockReadOnlyPropertiesOnce(); newRel.setProperty(GraphObject.type, relClass.getSimpleName()); } newRel.onRelationshipInstantiation(); return newRel; }
protected CharSequence getTitleOfGraphObject(T graphObject) { return (String) graphObject.getProperty(NAME); }