Revision 9515 org.gvsig.online/trunk/org.gvsig.online/org.gvsig.online.lib/org.gvsig.online.lib.impl/src/main/java/org/gvsig/online/lib/impl/workspace/OnlineWorkspaceImpl.java
OnlineWorkspaceImpl.java | ||
---|---|---|
19 | 19 |
import java.util.List; |
20 | 20 |
import java.util.Map; |
21 | 21 |
import java.util.Set; |
22 |
import java.util.logging.Level; |
|
23 | 22 |
import javax.json.JsonArray; |
24 | 23 |
import javax.json.JsonObject; |
25 | 24 |
import javax.json.JsonValue; |
... | ... | |
90 | 89 |
import static org.gvsig.online.lib.api.OnlineManager.ERR_CANT_UPDATE; |
91 | 90 |
import static org.gvsig.online.lib.api.OnlineManager.ERR_CANT_UPDATE_CLEAN; |
92 | 91 |
import static org.gvsig.online.lib.api.OnlineManager.ERR_ENTITY_NOT_EXISTS; |
93 |
import static org.gvsig.online.lib.api.OnlineManager.ERR_ENTITY_NOT_HAS_FEATURECODE; |
|
94 | 92 |
import static org.gvsig.online.lib.api.OnlineManager.ERR_INVALID_ENTITY; |
95 | 93 |
import static org.gvsig.online.lib.api.OnlineManager.ERR_NO_ERROR; |
96 | 94 |
import static org.gvsig.online.lib.api.OnlineManager.ERR_OFFLINE; |
... | ... | |
115 | 113 |
import static org.gvsig.online.lib.api.OnlineManager.STATE_LOCAL_UNMODIFIED; |
116 | 114 |
import static org.gvsig.online.lib.api.OnlineManager.STATE_REMOTE_NEW; |
117 | 115 |
import static org.gvsig.online.lib.api.OnlineManager.STATE_UNKNOWN; |
118 |
import static org.gvsig.online.lib.api.OnlineManager.TAG_ONLINE_DATAMODEL; |
|
119 |
import static org.gvsig.online.lib.api.OnlineManager.TAG_ONLINE_FIELDFORLABEL; |
|
120 |
import static org.gvsig.online.lib.api.OnlineManager.TAG_ONLINE_LABEL; |
|
121 | 116 |
import org.gvsig.online.lib.api.OnlineProject; |
122 | 117 |
import org.gvsig.online.lib.api.OnlineRuntimeException; |
123 | 118 |
import org.gvsig.online.lib.api.OnlineSite; |
124 |
import org.gvsig.online.lib.api.OnlineUserIdentificationRequester; |
|
125 |
import static org.gvsig.online.lib.api.OnlineUserIdentificationRequester.CHANGE_USER; |
|
126 | 119 |
import org.gvsig.online.lib.api.workingcopy.OnlineEntity; |
127 | 120 |
import org.gvsig.online.lib.api.workingcopy.OnlineRemoteChange; |
128 | 121 |
import org.gvsig.online.lib.api.workingcopy.OnlineWorkingcopy; |
... | ... | |
147 | 140 |
import org.gvsig.tools.dispose.DisposeUtils; |
148 | 141 |
import org.gvsig.tools.dispose.impl.AbstractDisposable; |
149 | 142 |
import static org.gvsig.tools.dynform.spi.DynFormSPIManager.TAG_DYNFORM_READONLY; |
150 |
import org.gvsig.tools.dynobject.Tags; |
|
151 | 143 |
import org.gvsig.tools.i18n.I18nManager; |
152 | 144 |
import org.gvsig.tools.logger.FilteredLogger; |
153 |
import org.gvsig.tools.observer.Notification; |
|
154 |
import org.gvsig.tools.observer.Observable; |
|
155 |
import org.gvsig.tools.observer.Observer; |
|
156 | 145 |
import org.gvsig.tools.patch.PatchGenerator; |
157 | 146 |
import org.gvsig.tools.resourcesstorage.ResourcesStorage; |
158 | 147 |
import org.gvsig.tools.swing.api.ChangeListenerHelper; |
... | ... | |
167 | 156 |
import org.slf4j.LoggerFactory; |
168 | 157 |
import org.gvsig.online.lib.api.workingcopy.OnlineChanges; |
169 | 158 |
|
159 |
import static org.gvsig.online.lib.api.OnlineManager.TAG_ONLINE_DATAMODEL; |
|
160 |
import static org.gvsig.online.lib.api.OnlineManager.TAG_ONLINE_FIELDFORLABEL; |
|
161 |
import static org.gvsig.online.lib.api.OnlineManager.TAG_ONLINE_LABEL; |
|
162 |
import org.gvsig.tools.dynobject.Tags; |
|
163 |
import static org.gvsig.online.lib.api.OnlineManager.ERR_ENTITY_NOT_HAS_FEATURECODE; |
|
164 |
|
|
170 | 165 |
/** |
171 | 166 |
* |
172 | 167 |
* @author jjdelcerro |
... | ... | |
180 | 175 |
public static final String CONFIG_WORKSPACE_CODE_CHANGE_ON_FIRST_USE = "CHANGE_ON_FIRST_USE"; |
181 | 176 |
public static final String CONFIG_WORKSPACE_LABEL_NAME = "WORKSPACE_LABEL"; |
182 | 177 |
public static final String CONFIG_PROJECT_NAME = "PROJECT"; |
183 |
public static final String CONFIG_USER_NAME = "USER"; |
|
178 |
// public static final String CONFIG_USER_NAME = "USER";
|
|
184 | 179 |
public static final String CONFIG_AUTHENTICATIONTOKEN_NAME = "AUTHENTICATIONTOKEN"; |
185 | 180 |
// public static final String CONFIG_REPOSITORY_ENTITY_CACHE_TIME_NAME = "REPOSITORY_ENTITY_CACHE_TIME"; |
186 | 181 |
public static final String CONFIG_OFFLINE = "OFFLINE"; |
... | ... | |
200 | 195 |
private final OnlineCodeGenerator codeGenerator; |
201 | 196 |
private final ChangeListenerHelper workspaceEntitiesChangeListeners; |
202 | 197 |
|
203 |
private Map<Integer/*projectid*/, String/*usercode*/> currentUserCodes; |
|
204 |
private Map<Integer/*projectid*/, String/*token*/> authenticationTokens; |
|
205 |
|
|
206 |
private OnlineUserIdentificationRequester userIdentificationRequester; |
|
207 | 198 |
// private long repositoryEntitiesCacheTime = 30000; |
208 | 199 |
private boolean offline; |
209 | 200 |
private String entityLabelTemplate; |
210 | 201 |
private boolean disposed = false; |
211 |
private Observer changeUserObserver; |
|
212 | 202 |
private WorkingArea currentWorkingArea; |
213 | 203 |
|
214 | 204 |
public OnlineWorkspaceImpl(JDBCServerExplorer wsexplorer, OnlineCodeGenerator codeGenerator, OnlineProject project, String label) { |
... | ... | |
224 | 214 |
DisposeUtils.bind(this.project); |
225 | 215 |
this.label = label; |
226 | 216 |
this.workspaceEntitiesChangeListeners = ToolsSwingLocator.getToolsSwingManager().createChangeListenerHelper(); |
227 |
this.currentUserCodes = null; |
|
228 |
this.authenticationTokens = null; |
|
229 |
this.userIdentificationRequester = null; |
|
230 | 217 |
this.offline = false; |
231 | 218 |
this.entityLabelTemplate = "${label}"; |
232 |
this.changeUserObserver = createChangeUserObserver(); |
|
233 | 219 |
} |
234 | 220 |
|
235 | 221 |
public OnlineWorkspaceImpl(JDBCServerExplorer wsexplorer, OnlineCodeGenerator codeGenerator, String newLabel) { |
... | ... | |
242 | 228 |
this.wsexplorer = wsexplorer; |
243 | 229 |
DisposeUtils.bind(wsexplorer); |
244 | 230 |
this.workspaceEntitiesChangeListeners = ToolsSwingLocator.getToolsSwingManager().createChangeListenerHelper(); |
245 |
this.userIdentificationRequester = null; |
|
246 | 231 |
|
247 | 232 |
VarsTable varsTable = new VarsTable(); |
248 | 233 |
if( StringUtils.isNotBlank(newLabel) ) { |
... | ... | |
252 | 237 |
Map<String,String> vars = varsTable.getVars(this, |
253 | 238 |
CONFIG_PROJECT_NAME, |
254 | 239 |
CONFIG_WORKSPACE_CODE_NAME, |
255 |
CONFIG_USER_NAME, |
|
240 |
// CONFIG_USER_NAME,
|
|
256 | 241 |
CONFIG_AUTHENTICATIONTOKEN_NAME, |
257 | 242 |
// CONFIG_REPOSITORY_ENTITY_CACHE_TIME_NAME, |
258 | 243 |
CONFIG_WORKSPACE_LABEL_NAME, |
... | ... | |
278 | 263 |
throw new RuntimeException("Can't retrieve repository from workspace '" + this.getMessageLabel() + "'"); |
279 | 264 |
} |
280 | 265 |
this.currentWorkingArea = (WorkingAreaImpl) Json.toObject(vars.get(CONFIG_CURRENT_WORKINGAREA)); |
281 |
this.setCurrentUserCode(this.project, vars.get(CONFIG_USER_NAME)); |
|
282 |
this.setAuthenticationToken(this.project, vars.get(CONFIG_AUTHENTICATIONTOKEN_NAME)); |
|
283 | 266 |
this.label = vars.get(CONFIG_WORKSPACE_LABEL_NAME); |
284 |
this.changeUserObserver = createChangeUserObserver(); |
|
285 | 267 |
|
286 | 268 |
// this.refreshCodeGeneratorSequence(); |
287 | 269 |
|
288 | 270 |
// LOGGER.debug("===: CREATE WORKSPACE "+ hexId(this)+ " (open code='"+this.code+"', label='"+this.label+"')"); |
289 | 271 |
} |
290 | 272 |
|
291 |
private org.gvsig.tools.observer.Observer createChangeUserObserver() { |
|
292 |
return (Observable observable, Object notification) -> { |
|
293 |
if(notification instanceof Notification) { |
|
294 |
Notification n = (Notification)notification; |
|
295 |
if(n.isOfType(CHANGE_USER)){ |
|
296 |
String userCode = (String) n.getValue(); |
|
297 |
setCurrentUserCode(project, userCode); |
|
298 |
VarsTable varsTable = new VarsTable(); |
|
299 |
varsTable.set(this,"USER", userCode); |
|
300 |
} |
|
301 |
} |
|
302 |
}; |
|
303 |
} |
|
304 |
|
|
273 |
|
|
305 | 274 |
@Override |
306 | 275 |
public String getCode() { |
307 | 276 |
return this.code; |
... | ... | |
1966 | 1935 |
} |
1967 | 1936 |
|
1968 | 1937 |
@Override |
1969 |
public void setUserIdentificationRequester(OnlineUserIdentificationRequester userIdentificationRequester) { |
|
1970 |
if(this.userIdentificationRequester != null){ |
|
1971 |
this.userIdentificationRequester.deleteObserver(changeUserObserver); |
|
1972 |
} |
|
1973 |
this.userIdentificationRequester = userIdentificationRequester; |
|
1974 |
this.userIdentificationRequester.addObserver(changeUserObserver); |
|
1975 |
} |
|
1976 |
|
|
1977 |
@Override |
|
1978 |
public OnlineUserIdentificationRequester getUserIdentificationRequester() { |
|
1979 |
return this.userIdentificationRequester; |
|
1980 |
} |
|
1981 |
|
|
1982 |
@Override |
|
1983 | 1938 |
public List<OnlineEntity> getEntitiesWithSelectedChanges() { |
1984 | 1939 |
|
1985 | 1940 |
List<OnlineEntity> entities = new ArrayList<>(); |
... | ... | |
2019 | 1974 |
|
2020 | 1975 |
@Override |
2021 | 1976 |
public void logout() { |
2022 |
VarsTable varsTable = new VarsTable(); |
|
2023 |
varsTable.delete(this, "USER"); |
|
2024 |
varsTable.delete(this, "AUTHENTICATIONTOKEN"); |
|
2025 |
this.currentUserCodes = null; |
|
2026 |
this.authenticationTokens = null; |
|
1977 |
this.getSite().logout(); |
|
2027 | 1978 |
} |
2028 | 1979 |
|
2029 | 1980 |
@Override |
... | ... | |
2524 | 2475 |
return builder.build(); |
2525 | 2476 |
} |
2526 | 2477 |
|
2527 |
public String getCurrentUserCode() { |
|
2528 |
return getCurrentUserCode(null); |
|
2529 |
} |
|
2530 |
|
|
2531 |
private String getCurrentUserCode(OnlineProject project) { |
|
2532 |
// Esto es por si acabamos cargando en un workspace |
|
2533 |
// tablas de mas de un proyecto del mismo site. |
|
2534 |
if( this.currentUserCodes == null ) { |
|
2535 |
return null; |
|
2536 |
} |
|
2537 |
int projectid; |
|
2538 |
if( project == null ) { |
|
2539 |
projectid = this.getProject().getId(); |
|
2540 |
} else { |
|
2541 |
projectid = project.getId(); |
|
2542 |
} |
|
2543 |
return this.currentUserCodes.get(projectid); |
|
2544 |
} |
|
2545 |
|
|
2546 |
private void setCurrentUserCode(OnlineProject project, String userCode) { |
|
2547 |
int projectid; |
|
2548 |
if( project == null ) { |
|
2549 |
projectid = this.getProject().getId(); |
|
2550 |
} else { |
|
2551 |
projectid = project.getId(); |
|
2552 |
} |
|
2553 |
if( this.currentUserCodes == null ) { |
|
2554 |
this.currentUserCodes = new HashMap<>(); |
|
2555 |
} |
|
2556 |
this.currentUserCodes.put(projectid, userCode); |
|
2557 |
} |
|
2558 |
|
|
2559 |
private String getAuthenticationToken(OnlineProject project) { |
|
2560 |
if( this.authenticationTokens == null ) { |
|
2561 |
return null; |
|
2562 |
} |
|
2563 |
int projectid; |
|
2564 |
if( project == null ) { |
|
2565 |
projectid = this.getProject().getId(); |
|
2566 |
} else { |
|
2567 |
projectid = project.getId(); |
|
2568 |
} |
|
2569 |
return this.authenticationTokens.get(projectid); |
|
2570 |
} |
|
2571 |
|
|
2572 |
private void setAuthenticationToken(OnlineProject project, String token) { |
|
2573 |
int projectid; |
|
2574 |
if( project == null ) { |
|
2575 |
projectid = this.getProject().getId(); |
|
2576 |
} else { |
|
2577 |
projectid = project.getId(); |
|
2578 |
} |
|
2579 |
if( this.authenticationTokens == null ) { |
|
2580 |
this.authenticationTokens = new HashMap<>(); |
|
2581 |
} |
|
2582 |
this.authenticationTokens.put(projectid, token); |
|
2583 |
} |
|
2584 |
|
|
2585 | 2478 |
public boolean isAResourceTable(String entityName) { |
2586 | 2479 |
// Deberia comprobar gvsigd_resources? |
2587 | 2480 |
return false; |
... | ... | |
3312 | 3205 |
SimpleTaskStatus.FAKE_STATUS |
3313 | 3206 |
); |
3314 | 3207 |
File f = ((HasAFile) this.getExplorerParameters()).getFile(); |
3315 |
File tmpRemote = ToolsLocator.getFoldersManager().getUniqueFile(H2SpatialUtils.removeH2FileNameExtension(f.getAbsolutePath())+"_tmp_"+entity.getEntityName()); |
|
3208 |
String tmpPathname = H2SpatialUtils.removeH2FileNameExtension(f.getAbsolutePath())+"_tmp_"+entity.getEntityName(); |
|
3209 |
// File tmpRemote = new File(tmpPathname); |
|
3210 |
File tmpRemote = ToolsLocator.getFoldersManager().getUniqueFile(tmpPathname); |
|
3316 | 3211 |
DataManager dataManager = DALLocator.getDataManager(); |
3317 | 3212 |
DataServerExplorerParameters expParameters = DALLocator.getDataManager().createServerExplorerParameters(FeatureStore.H2SPATIAL_PROVIDER_NAME); |
3318 | 3213 |
((HasAFile) expParameters).setFile(tmpRemote); |
Also available in: Unified diff