throw new CoreException(new Status(IStatus.ERROR, ServerConstants.PI_SERVER_CORE, 1, "SimpleMetaStore.createProject: workspace id is null.", null));
}
if (projectInfo.getFullName() == null) {
throw new CoreException(new Status(IStatus.ERROR, ServerConstants.PI_SERVER_CORE, 1, "SimpleMetaStore.createProject: project name is null.", null));
}
WorkspaceInfo workspaceInfo;
try {
workspaceInfo = readWorkspace(projectInfo.getWorkspaceId());
} catch (CoreException exception) {
throw new CoreException(new Status(IStatus.ERROR, ServerConstants.PI_SERVER_CORE, 1, "SimpleMetaStore.createProject: could not find workspace with id:" + projectInfo.getWorkspaceId() + ", workspace does not exist.", null));
}
if (workspaceInfo == null) {
throw new CoreException(new Status(IStatus.ERROR, ServerConstants.PI_SERVER_CORE, 1, "SimpleMetaStore.createProject: could not find workspace with id:" + projectInfo.getWorkspaceId() + ", workspace does not exist.", null));
}
String userId = SimpleMetaStoreUtil.decodeUserIdFromWorkspaceId(projectInfo.getWorkspaceId());
String encodedWorkspaceName = SimpleMetaStoreUtil.decodeWorkspaceNameFromWorkspaceId(projectInfo.getWorkspaceId());
String projectId = SimpleMetaStoreUtil.encodeProjectIdFromProjectName(projectInfo.getFullName());
projectInfo.setUniqueId(projectId);
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put(SimpleMetaStore.ORION_VERSION, VERSION);
jsonObject.put(MetadataInfo.UNIQUE_ID, projectInfo.getUniqueId());
jsonObject.put("WorkspaceId", projectInfo.getWorkspaceId());
jsonObject.put(UserConstants2.FULL_NAME, projectInfo.getFullName());
if (projectInfo.getContentLocation() != null) {
URI contentLocation = projectInfo.getContentLocation();
String encodedContentLocation = SimpleMetaStoreUtil.encodeProjectContentLocation(contentLocation.toString());
jsonObject.put("ContentLocation", encodedContentLocation);
}
JSONObject properties = updateProperties(jsonObject, projectInfo);
jsonObject.put("Properties", properties);
} catch (JSONException e) {
throw new CoreException(new Status(IStatus.ERROR, ServerConstants.PI_SERVER_CORE, 1, "SimpleMetaStore.createProject: could not create project: " + projectInfo.getFullName() + " for user " + userId, e));
}
File userMetaFolder = SimpleMetaStoreUtil.readMetaUserFolder(getRootLocation(), userId);
File workspaceMetaFolder = SimpleMetaStoreUtil.readMetaFolder(userMetaFolder, encodedWorkspaceName);
if (!SimpleMetaStoreUtil.isMetaFolder(workspaceMetaFolder, projectId)) {
// try to create the project folder if the folder is not linked
if ((projectInfo.getContentLocation() == null || projectInfo.getProjectStore().equals(getDefaultContentLocation(projectInfo))) && !SimpleMetaStoreUtil.createMetaFolder(workspaceMetaFolder, projectId)) {
throw new CoreException(new Status(IStatus.ERROR, ServerConstants.PI_SERVER_CORE, 1, "SimpleMetaStore.createProject: could not create project: " + projectInfo.getFullName() + " for user " + userId, null));
}
}
if (!SimpleMetaStoreUtil.createMetaFile(userMetaFolder, projectId, jsonObject)) {
throw new CoreException(new Status(IStatus.ERROR, ServerConstants.PI_SERVER_CORE, 1, "SimpleMetaStore.createProject: could not create project: " + projectInfo.getFullName() + " for user " + userId, null));
}
// Update the workspace with the new projectName
List<String> newProjectNames = new ArrayList<String>();
newProjectNames.addAll(workspaceInfo.getProjectNames());
newProjectNames.add(projectInfo.getFullName());
workspaceInfo.setProjectNames(newProjectNames);
updateWorkspace(workspaceInfo);
}