001 package org.deepamehta.plugins.twitter.migrations; 002 003 import de.deepamehta.core.Topic; 004 import de.deepamehta.core.TopicType; 005 import de.deepamehta.core.model.*; 006 import de.deepamehta.core.service.Migration; 007 import java.util.logging.Logger; 008 009 010 /** 011 * A basic wrapper for the public Twitter Search API and DeepaMehta 4. 012 * 013 * @version 1.2 014 * @author Malte Reißig (<malte@mikromedia.de>) 015 * @website http://github.com/mukil 016 * 017 */ 018 019 public class Migration2 extends Migration { 020 021 private Logger logger = Logger.getLogger(getClass().getName()); 022 023 private final static String TWEET_URI = "org.deepamehta.twitter.tweet"; 024 private final static String TWEET_ID_URI = "org.deepamehta.twitter.tweet_id"; 025 private final static String TWEET_TIME_URI = "org.deepamehta.twitter.tweet_time"; 026 private final static String TWEET_CONTENT_URI = "org.deepamehta.twitter.tweet_content"; 027 private final static String TWEET_ENTITIES_URI = "org.deepamehta.twitter.tweet_entities"; 028 private final static String TWEET_METADADA_URI = "org.deepamehta.twitter.tweet_metadata"; 029 private final static String TWEET_SOURCE_BUTTON_URI = "org.deepamehta.twitter.tweet_source_button"; 030 private final static String TWEET_LOCATION_URI = "org.deepamehta.twitter.tweet_location"; 031 private final static String TWEET_FAVOURITE_COUNT_URI = "org.deepamehta.twitter.tweet_favourite_count"; 032 private final static String TWEET_WITHHELD_DMCA_URI = "org.deepamehta.twitter.tweet_withheld_copyright"; 033 private final static String TWEET_WITHHELD_IN_URI = "org.deepamehta.twitter.tweet_withheld_in"; 034 private final static String TWEET_WITHHELD_SCOPE_URI = "org.deepamehta.twitter.tweet_withheld_scope"; 035 private final static String TWEETED_TO_STATUS_ID = "org.deepamehta.twitter.tweeted_to_status_id"; 036 037 private final static String TWITTER_USER_URI = "org.deepamehta.twitter.user"; 038 private final static String TWITTER_USER_ID_URI = "org.deepamehta.twitter.user_id"; 039 private final static String TWITTER_USER_NAME_URI = "org.deepamehta.twitter.user_name"; 040 private final static String TWITTER_USER_IMAGE_URI = "org.deepamehta.twitter.user_image_url"; 041 042 private final static String TWITTER_SEARCH_URI = "org.deepamehta.twitter.search"; 043 private final static String TWITTER_SEARCH_LANG_URI = "org.deepamehta.twitter.search_language"; 044 private final static String TWITTER_SEARCH_LOCATION_URI = "org.deepamehta.twitter.search_location"; 045 private final static String TWITTER_SEARCH_TYPE_URI = "org.deepamehta.twitter.search_result_type"; 046 private final static String TWITTER_SEARCH_NEXT_PAGE_URI = "org.deepamehta.twitter.search_next_page"; 047 private final static String TWITTER_SEARCH_REFRESH_URL_URI = "org.deepamehta.twitter.search_refresh_url"; 048 private final static String TWITTER_SEARCH_MAX_TWEET_URI = "org.deepamehta.twitter.search_last_tweet_id"; 049 private final static String TWITTER_SEARCH_RESULT_SIZE_URI = "org.deepamehta.twitter.search_result_size"; 050 private final static String TWITTER_SEARCH_TIME_URI = "org.deepamehta.twitter.last_search_time"; 051 052 private final static String GEO_COORDINATE_URI = "dm4.geomaps.geo_coordinate"; 053 054 private String COMPOSITION_DEF_EDGE_TYPE = "dm4.core.composition_def"; 055 private String ROLE_PARENT_TYPE_URI = "dm4.core.parent_type"; 056 private String ROLE_CHILD_TYPE_URI = "dm4.core.child_type"; 057 058 private final static String DEEPAMEHTA_USERNAME_URI = "dm4.accesscontrol.username"; 059 060 061 private String WS_WEB_RESEARCH_URI = "org.deepamehta.workspaces.web_research"; 062 063 @Override 064 public void run() { 065 066 // 1) create "Twitter Research"-Workspace 067 TopicModel workspace = new TopicModel(WS_WEB_RESEARCH_URI, "dm4.workspaces.workspace"); 068 Topic ws = dms.createTopic(workspace, null); 069 ws.setSimpleValue("Twitter Research"); 070 // 2) assign "admin" username to "Twitter Research"-Workspace 071 Topic administrator = dms.getTopic(DEEPAMEHTA_USERNAME_URI, new SimpleValue("admin"), true); 072 assignWorkspace(administrator); 073 // 3) assign all types to our new workspace 074 TopicType twitterSearchType = dms.getTopicType(TWITTER_SEARCH_URI); 075 TopicType searchLang = dms.getTopicType(TWITTER_SEARCH_LANG_URI); 076 TopicType searchLocation = dms.getTopicType(TWITTER_SEARCH_LOCATION_URI); 077 TopicType searchType = dms.getTopicType(TWITTER_SEARCH_TYPE_URI); 078 TopicType searchNextPage = dms.getTopicType(TWITTER_SEARCH_NEXT_PAGE_URI); 079 TopicType searchRefresh = dms.getTopicType(TWITTER_SEARCH_REFRESH_URL_URI); 080 TopicType searchLastId = dms.getTopicType(TWITTER_SEARCH_MAX_TWEET_URI); 081 TopicType searchResultSize = dms.getTopicType(TWITTER_SEARCH_RESULT_SIZE_URI); 082 TopicType searchTime = dms.getTopicType(TWITTER_SEARCH_TIME_URI); 083 // 084 TopicType user = dms.getTopicType(TWITTER_USER_URI); 085 TopicType userId = dms.getTopicType(TWITTER_USER_ID_URI); 086 TopicType userName = dms.getTopicType(TWITTER_USER_NAME_URI); 087 TopicType userImageUrl = dms.getTopicType(TWITTER_USER_IMAGE_URI); 088 // 089 TopicType tweet = dms.getTopicType(TWEET_URI); 090 TopicType tweetId = dms.getTopicType(TWEET_ID_URI); 091 TopicType tweetContent = dms.getTopicType(TWEET_CONTENT_URI); 092 TopicType tweetTimestamp = dms.getTopicType(TWEET_TIME_URI); 093 TopicType tweetEntities = dms.getTopicType(TWEET_ENTITIES_URI); 094 TopicType tweetMetadata = dms.getTopicType(TWEET_METADADA_URI); 095 TopicType tweetSourceButton = dms.getTopicType(TWEET_SOURCE_BUTTON_URI); 096 TopicType tweetLocation = dms.getTopicType(TWEET_LOCATION_URI); 097 TopicType tweetFavouriteCount = dms.getTopicType(TWEET_FAVOURITE_COUNT_URI); 098 TopicType tweetWithheldCopy = dms.getTopicType(TWEET_WITHHELD_DMCA_URI); 099 TopicType tweetWithheldIn = dms.getTopicType(TWEET_WITHHELD_IN_URI); 100 TopicType tweetWithheldScope = dms.getTopicType(TWEET_WITHHELD_SCOPE_URI); 101 TopicType tweetedToStatusId = dms.getTopicType(TWEETED_TO_STATUS_ID); 102 // 103 assignWorkspace(twitterSearchType); 104 assignWorkspace(searchLang); 105 assignWorkspace(searchLocation); 106 assignWorkspace(searchType); 107 assignWorkspace(searchNextPage); 108 assignWorkspace(searchRefresh); 109 assignWorkspace(searchLastId); 110 assignWorkspace(searchResultSize); 111 assignWorkspace(searchTime); 112 // 113 assignWorkspace(user); 114 assignWorkspace(userId); 115 assignWorkspace(userName); 116 assignWorkspace(userImageUrl); 117 // 118 assignWorkspace(tweet); 119 assignWorkspace(tweetId); 120 assignWorkspace(tweetContent); 121 assignWorkspace(tweetTimestamp); 122 assignWorkspace(tweetEntities); 123 assignWorkspace(tweetSourceButton); 124 assignWorkspace(tweetMetadata); 125 assignWorkspace(tweetLocation); 126 assignWorkspace(tweetFavouriteCount); 127 assignWorkspace(tweetWithheldCopy); 128 assignWorkspace(tweetWithheldScope); 129 assignWorkspace(tweetWithheldIn); 130 assignWorkspace(tweetedToStatusId); 131 // 4) Model "Geo Coordinate" to "Tweet" 132 TopicType tweet_type = dms.getTopicType(TWEET_URI); 133 tweet_type.addAssocDef(new AssociationDefinitionModel( 134 COMPOSITION_DEF_EDGE_TYPE, TWEET_URI, GEO_COORDINATE_URI, "dm4.core.one", "dm4.core.one")); 135 } 136 137 // === Workspace === 138 139 private void assignWorkspace(Topic topic) { 140 Topic defaultWorkspace = dms.getTopic("uri", new SimpleValue(WS_WEB_RESEARCH_URI), false); 141 dms.createAssociation(new AssociationModel("dm4.core.aggregation", 142 new TopicRoleModel(topic.getId(), "dm4.core.parent"), 143 new TopicRoleModel(defaultWorkspace.getId(), "dm4.core.child") 144 ), null); 145 } 146 147 }