Static item properties parser

This commit is contained in:
Fabio Sinibaldi 2021-05-14 11:30:17 +02:00
parent a371578598
commit ad9e913202
6 changed files with 76 additions and 9 deletions

View File

@ -1,15 +1,18 @@
package org.gcube.usecases.ws.thredds;
import java.io.File;
import java.util.Map;
import java.util.Set;
import org.gcube.usecases.ws.thredds.engine.impl.ProcessDescriptor;
import org.gcube.usecases.ws.thredds.engine.impl.ProcessStatus;
import org.gcube.usecases.ws.thredds.engine.impl.SynchEngineImpl;
import org.gcube.usecases.ws.thredds.engine.impl.WorkspaceUtils;
import org.gcube.usecases.ws.thredds.faults.InternalException;
import org.gcube.usecases.ws.thredds.faults.ProcessNotFoundException;
import org.gcube.usecases.ws.thredds.faults.WorkspaceInteractionException;
import org.gcube.usecases.ws.thredds.faults.WorkspaceNotSynchedException;
import org.gcube.usecases.ws.thredds.model.ContainerType;
import org.gcube.usecases.ws.thredds.model.SyncEngineStatusDescriptor;
import org.gcube.usecases.ws.thredds.model.SyncFolderDescriptor;
import org.gcube.usecases.ws.thredds.model.SyncOperationCallBack;
@ -50,6 +53,12 @@ public interface SyncEngine {
*/
public void unsetSynchronizedFolder(String folderId,boolean deleteRemoteContent) throws WorkspaceInteractionException, InternalException;
/**
* NB Method To Be Implemented
*
* @param elementId
* @return
*/
public SynchronizedElementInfo getInfo(String elementId);
@ -92,4 +101,9 @@ public interface SyncEngine {
public SynchFolderConfiguration getConfig(String fodlerId) throws WorkspaceInteractionException, WorkspaceNotSynchedException;
public static SynchronizedElementInfo parseInfo(Map<String,Object> itemProperties,ContainerType itemType)throws WorkspaceNotSynchedException{
return WorkspaceUtils.getInfo(itemProperties, org.gcube.common.storagehub.client.dsl.ContainerType.valueOf(itemType.toString()));
}
}

View File

@ -2,6 +2,7 @@ package org.gcube.usecases.ws.thredds.engine.impl;
import java.io.File;
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
@ -28,6 +29,7 @@ import org.gcube.usecases.ws.thredds.faults.WorkspaceInteractionException;
import org.gcube.usecases.ws.thredds.faults.WorkspaceLockedException;
import org.gcube.usecases.ws.thredds.faults.WorkspaceNotSynchedException;
import org.gcube.usecases.ws.thredds.model.CompletionCallback;
import org.gcube.usecases.ws.thredds.model.ContainerType;
import org.gcube.usecases.ws.thredds.model.SyncEngineStatusDescriptor;
import org.gcube.usecases.ws.thredds.model.SyncFolderDescriptor;
import org.gcube.usecases.ws.thredds.model.SyncOperationCallBack;
@ -333,4 +335,7 @@ public class SynchEngineImpl implements SyncEngine{
public SynchFolderConfiguration getConfig(String folderId) throws WorkspaceInteractionException, WorkspaceNotSynchedException {
return new WorkspaceFolderManager(folderId).getSynchConfiguration();
}
}

View File

@ -125,10 +125,10 @@ public class WorkspaceFolderManager {
log.info("Resulting status for {} IS {} ",folderId,resultingStatus);
return new SyncFolderDescriptor(
return new SyncFolderDescriptor(resultingStatus,
this.folderId,
this.theFolder.get().getPath(),
config,new SynchronizedElementInfo(resultingStatus));
config,false);
}catch(StorageHubException e) {
throw new WorkspaceInteractionException(e);
}

View File

@ -28,8 +28,10 @@ import org.gcube.usecases.ws.thredds.faults.InternalException;
import org.gcube.usecases.ws.thredds.faults.ItemNotFoundException;
import org.gcube.usecases.ws.thredds.faults.RemoteFileNotFoundException;
import org.gcube.usecases.ws.thredds.faults.WorkspaceInteractionException;
import org.gcube.usecases.ws.thredds.faults.WorkspaceNotSynchedException;
import org.gcube.usecases.ws.thredds.model.StepReport;
import org.gcube.usecases.ws.thredds.model.SynchFolderConfiguration;
import org.gcube.usecases.ws.thredds.model.SynchronizedElementInfo;
import org.gcube.usecases.ws.thredds.model.SynchronizedElementInfo.SynchronizationStatus;
import lombok.extern.slf4j.Slf4j;
@ -361,6 +363,12 @@ public class WorkspaceUtils {
}
public static SynchFolderConfiguration loadConfiguration(ItemContainer<?> item) throws StorageHubException, WorkspaceInteractionException {
if(item.getType().equals(ContainerType.FOLDER)) {
Metadata meta=item.get().getMetadata();
@ -448,5 +456,20 @@ public class WorkspaceUtils {
throw new ItemNotFoundException("Unable to find "+path);
}
//************** parsing properties
public static SynchronizedElementInfo getInfo(Map<String,Object> map,ContainerType type) throws WorkspaceNotSynchedException {
if(!(map.containsKey(Constants.WorkspaceProperties.TBS)&&Boolean.parseBoolean(map.get(Constants.WorkspaceProperties.TBS)+"")))
throw new WorkspaceNotSynchedException("Item is not to be synchronized");
SynchronizationStatus status = SynchronizationStatus.valueOf(map.get(Constants.WorkspaceProperties.LAST_UPDATE_STATUS)+"");
SynchronizedElementInfo toReturn=new SynchronizedElementInfo(status);
//TODO PARSE ALL PROPERTIES
return toReturn;
}
}

View File

@ -0,0 +1,10 @@
package org.gcube.usecases.ws.thredds.model;
public enum ContainerType {
FOLDER,
FILE,
GENERIC_ITEM,
URL
}

View File

@ -2,13 +2,13 @@ package org.gcube.usecases.ws.thredds.model;
import org.gcube.usecases.ws.thredds.engine.impl.ProcessDescriptor;
import lombok.Data;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
@Data
@RequiredArgsConstructor
public class SyncFolderDescriptor {
@Getter
@Setter
public class SyncFolderDescriptor extends SynchronizedElementInfo{
@NonNull
private String folderId;
@ -21,8 +21,23 @@ public class SyncFolderDescriptor {
private Boolean isLocked=false;
public SyncFolderDescriptor(SynchronizationStatus status, String folderId, String folderPath,
SynchFolderConfiguration configuration, Boolean isLocked) {
super(status);
this.folderId = folderId;
this.folderPath = folderPath;
this.configuration = configuration;
this.isLocked = isLocked;
}
private ProcessDescriptor localProcessDescriptor=null;
@NonNull
private SynchronizedElementInfo info;
}