diff --git a/src/Database/Models/ProjectModel.cs b/src/Database/Models/ProjectModel.cs
index ba9390d7527113a4527a3bb9878c2cbf842ea50f..d985633e159ba45545ce5ed754c8191d12179fee 100644
--- a/src/Database/Models/ProjectModel.cs
+++ b/src/Database/Models/ProjectModel.cs
@@ -19,7 +19,7 @@ namespace Coscine.Database.Models
return
(from tableEntry in GetITableFromDatabase(db)
where tableEntry.Id == id
- && tableEntry.Deleted == true
+ && tableEntry.Deleted
select tableEntry).Count() == 1;
});
}
@@ -32,7 +32,7 @@ namespace Coscine.Database.Models
return
(from tableEntry in GetITableFromDatabase(db).AsExpandable()
where expression.Invoke(tableEntry) == id
- && tableEntry.Deleted == false
+ && !tableEntry.Deleted
select tableEntry).FirstOrDefault();
});
}
@@ -61,7 +61,7 @@ namespace Coscine.Database.Models
return
(from tableEntry in GetITableFromDatabase(db).AsExpandable()
where whereClause.Invoke(tableEntry)
- && tableEntry.Deleted == false
+ && !tableEntry.Deleted
select tableEntry).FirstOrDefault();
});
}
@@ -72,7 +72,7 @@ namespace Coscine.Database.Models
{
return
(from tableEntry in GetITableFromDatabase(db)
- where tableEntry.Deleted == false
+ where !tableEntry.Deleted
select tableEntry).ToList();
});
}
@@ -84,7 +84,7 @@ namespace Coscine.Database.Models
return
(from tableEntry in GetITableFromDatabase(db).AsExpandable()
where whereClause.Invoke(tableEntry)
- && tableEntry.Deleted == false
+ && !tableEntry.Deleted
select tableEntry).ToList();
});
}
@@ -107,18 +107,12 @@ namespace Coscine.Database.Models
public override int Delete(Project databaseObject)
{
databaseObject.Deleted = true;
- return DatabaseConnection.ConnectToDatabase((db) =>
- {
- return (int)db.Update(databaseObject).State;
- });
+ return DatabaseConnection.ConnectToDatabase((db) => (int)db.Update(databaseObject).State);
}
public int HardDelete(Project databaseObject)
{
- return DatabaseConnection.ConnectToDatabase((db) =>
- {
- return (int) db.Remove(databaseObject).State;
- });
+ return DatabaseConnection.ConnectToDatabase((db) => (int)db.Remove(databaseObject).State);
}
public int HardDelete(Expression<Func<Project, bool>> whereClause)
@@ -126,8 +120,8 @@ namespace Coscine.Database.Models
return DatabaseConnection.ConnectToDatabase((db) =>
{
return (int)db.Remove(from tableEntry in GetITableFromDatabase(db).AsExpandable()
- where whereClause.Invoke(tableEntry)
- select tableEntry).State;
+ where whereClause.Invoke(tableEntry)
+ select tableEntry).State;
});
}
@@ -177,7 +171,7 @@ namespace Coscine.Database.Models
join pi in db.ProjectInstitutes on p.Id equals pi.ProjectId into joinedPi
from jpi in joinedPi.DefaultIfEmpty()
- where p.Deleted == false
+ where !p.Deleted
group jpi by jpi.OrganizationUrl into g
select new OrganizationCountObject(g.Key, g.Count())).ToList();
});
@@ -189,8 +183,8 @@ namespace Coscine.Database.Models
var slug = projectObject.DisplayName;
slug = slug.ToLower();
slug = Regex.Replace(slug, @"[\s-]+", "-");
- slug = Regex.Replace(slug, @"[^a-z0-9-]*|", "");
- slug = Regex.Replace(slug, @"^-|-$", "");
+ slug = Regex.Replace(slug, "[^a-z0-9-]*|", "");
+ slug = Regex.Replace(slug, "^-|-$", "");
Random r = new Random();
int rInt = r.Next(0, 9000000) + 1000000;
@@ -211,7 +205,7 @@ namespace Coscine.Database.Models
while (GetBySlug(fullSlug + rInt) != null)
{
rInt++;
- };
+ }
fullSlug += rInt;
}
@@ -333,11 +327,11 @@ namespace Coscine.Database.Models
public IEnumerable<Project> GetTopLevelWithAccess(User user, params string[] allowedAccess)
{
- return GetWithAccess(user, allowedAccess, (allowedProjectIds) => GetAllWhere((project) =>
+ return GetWithAccess(user, allowedAccess, (_) => GetAllWhere((project) =>
(
- // all accessable projects that have no parents
- (!project.SubProjectSubProjectNavigations.Any())
- || // all accessable projects that have no accessable parents
+ // all accessible projects that have no parents
+ (project.SubProjectSubProjectNavigations.Count == 0)
+ || // all accessible projects that have no accessible parents
(
project.SubProjectSubProjectNavigations.All(
(parentProjects) =>
@@ -436,7 +430,7 @@ namespace Coscine.Database.Models
{
list = GetAllWhere((dbProject) => (from subProject in dbProject.SubProjectProjects
where subProject.SubProjectId == currentProject.Id
- && subProject.Project.Deleted == false
+ && !subProject.Project.Deleted
select subProject).Any());
if (list.Any())
@@ -530,6 +524,5 @@ namespace Coscine.Database.Models
}
return $"{counted}/{maxCount}";
}
-
}
-}
+}
\ No newline at end of file
diff --git a/src/Database/Models/RDSResourceTypeModel.cs b/src/Database/Models/RDSResourceTypeModel.cs
index 7a08f070307d392c0ee883eb409bbc5183e9946c..18f66d12e8031f08c5e34301979a0e2b874dd64d 100644
--- a/src/Database/Models/RDSResourceTypeModel.cs
+++ b/src/Database/Models/RDSResourceTypeModel.cs
@@ -25,14 +25,16 @@ namespace Coscine.Database.Models
public Dictionary<string, string> GetResourceTypeOptions(Guid id)
{
- var dictionary = new Dictionary<string, string>();
var resourceType = GetById(id);
- dictionary.Add("accessKey", resourceType.AccessKey);
- dictionary.Add("secretKey", resourceType.SecretKey);
- dictionary.Add("bucketname", resourceType.BucketName);
- dictionary.Add("endpoint", resourceType.Endpoint);
- dictionary.Add("size", $"{resourceType.Size}");
+ var dictionary = new Dictionary<string, string>
+ {
+ { "accessKey", resourceType.AccessKey },
+ { "secretKey", resourceType.SecretKey },
+ { "bucketname", resourceType.BucketName },
+ { "endpoint", resourceType.Endpoint },
+ { "size", $"{resourceType.Size}" }
+ };
return dictionary;
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Database/Models/RdsS3ResourceTypeModel.cs b/src/Database/Models/RdsS3ResourceTypeModel.cs
index 2c61f7f6241ae4f02f92e171f89eb4d3bfcbb847..84dc0c8f2aa4400892d59ff3a3143400b2cc852e 100644
--- a/src/Database/Models/RdsS3ResourceTypeModel.cs
+++ b/src/Database/Models/RdsS3ResourceTypeModel.cs
@@ -24,18 +24,20 @@ namespace Coscine.Database.Models
public Dictionary<string, string> GetResourceTypeOptions(Guid id)
{
- var dictionary = new Dictionary<string, string>();
var resourceType = GetById(id);
- dictionary.Add("accessKey", resourceType.AccessKey);
- dictionary.Add("secretKey", resourceType.SecretKey);
- dictionary.Add("accessKeyRead", resourceType.AccessKeyRead);
- dictionary.Add("secretKeyRead", resourceType.SecretKeyRead);
- dictionary.Add("accessKeyWrite", resourceType.AccessKeyWrite);
- dictionary.Add("secretKeyWrite", resourceType.SecretKeyWrite);
- dictionary.Add("bucketname", resourceType.BucketName);
- dictionary.Add("endpoint", resourceType.Endpoint);
- dictionary.Add("size", $"{resourceType.Size}");
+ var dictionary = new Dictionary<string, string>
+ {
+ { "accessKey", resourceType.AccessKey },
+ { "secretKey", resourceType.SecretKey },
+ { "accessKeyRead", resourceType.AccessKeyRead },
+ { "secretKeyRead", resourceType.SecretKeyRead },
+ { "accessKeyWrite", resourceType.AccessKeyWrite },
+ { "secretKeyWrite", resourceType.SecretKeyWrite },
+ { "bucketname", resourceType.BucketName },
+ { "endpoint", resourceType.Endpoint },
+ { "size", $"{resourceType.Size}" }
+ };
return dictionary;
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Database/Models/ResourceModel.cs b/src/Database/Models/ResourceModel.cs
index d5ab2d09082d099569e5f9ae44a5f9016d31a1bf..ee82ffa61731498a879c89f26590a43d6e64b1e3 100644
--- a/src/Database/Models/ResourceModel.cs
+++ b/src/Database/Models/ResourceModel.cs
@@ -14,6 +14,15 @@ namespace Coscine.Database.Models
public class ResourceModel : DatabaseModel<Resource>
{
private readonly IConfiguration _configuration = new ConsulConfiguration();
+
+ private static readonly Dictionary<string, string> _configs = new Dictionary<string, string>
+ {
+ { "rds", "coscine/global/rds/ecs-rwth/rds" },
+ { "rdsude", "coscine/global/rds/ecs-ude/rds" },
+ { "rdss3", "coscine/global/rds/ecs-rwth/rds-s3" },
+ { "rdss3ude", "coscine/global/rds/ecs-ude/rds-s3" }
+ };
+
public Resource StoreFromObject(ResourceObject resourceObject)
{
if (!resourceObject.Disciplines.Any() || resourceObject.ResourceTypeOption == null)
@@ -48,7 +57,7 @@ namespace Coscine.Database.Models
}
catch (Exception)
{
- // Makes sure to delete all FK refrences, otherwise a delete is not possible
+ // Makes sure to delete all FK references, otherwise a delete is not possible
DeleteResource(resource);
throw;
}
@@ -100,7 +109,7 @@ namespace Coscine.Database.Models
join rt in db.ResourceTypes on r.TypeId equals rt.Id into joinedRt
from jrt in joinedRt.DefaultIfEmpty()
- where jp.Deleted == false &&
+ where !jp.Deleted &&
IsLikeRds(jrt.DisplayName)
group r by jpi.OrganizationUrl into g
select new OrganizationResourceListObject(g.Key, g.ToList())).ToList();
@@ -120,13 +129,14 @@ namespace Coscine.Database.Models
}
else
{
+ var prefix = _configs[resource.Type.DisplayName];
RdsresourceType rdsResourceType = new RdsresourceType()
{
BucketName = resource.Id.ToString(),
Size = rdsResourceTypeObject.Size,
- AccessKey = _configuration.GetString("coscine/global/rds/ecs-rwth/rds/object_user_name"),
- SecretKey = _configuration.GetString("coscine/global/rds/ecs-rwth/rds/object_user_secretkey"),
- Endpoint = _configuration.GetString("coscine/global/rds/ecs-rwth/rds/s3_endpoint"),
+ AccessKey = _configuration.GetString($"{prefix}/object_user_name"),
+ SecretKey = _configuration.GetString($"{prefix}/object_user_secretkey"),
+ Endpoint = _configuration.GetString($"{prefix}/s3_endpoint"),
};
rdsResourceTypeModel.Insert(rdsResourceType);
resource.ResourceTypeOptionId = rdsResourceType.Id;
@@ -209,16 +219,17 @@ namespace Coscine.Database.Models
}
else
{
+ var prefix = _configs[resource.Type.DisplayName];
var rdsS3ResourceType = new RdsS3resourceType()
{
BucketName = resource.Id.ToString(),
- AccessKey = _configuration.GetString("coscine/global/rds/ecs-rwth/rds-s3/object_user_name"),
- SecretKey = _configuration.GetString("coscine/global/rds/ecs-rwth/rds-s3/object_user_secretkey"),
+ AccessKey = _configuration.GetString($"{prefix}/object_user_name"),
+ SecretKey = _configuration.GetString($"{prefix}/object_user_secretkey"),
AccessKeyRead = $"read_{resource.Id}",
SecretKeyRead = RandomHelper.GenerateRandomChunk(32),
AccessKeyWrite = $"write_{resource.Id}",
SecretKeyWrite = RandomHelper.GenerateRandomChunk(32),
- Endpoint = _configuration.GetString("coscine/global/rds/ecs-rwth/rds-s3/s3_endpoint"),
+ Endpoint = _configuration.GetString($"{prefix}/s3_endpoint"),
Size = rdsS3ResourceTypeObject.Size,
};
rdsS3ResourceTypeModel.Insert(rdsS3ResourceType);
@@ -418,7 +429,6 @@ namespace Coscine.Database.Models
LinkedResourceTypeModel linkedResourceTypeModel = new LinkedResourceTypeModel();
var linkedResourceType = linkedResourceTypeModel.GetById(resource.ResourceTypeOptionId.Value);
resourceTypeOptionObject = new LinkedResourceTypeObject(linkedResourceType.Id);
-
}
else if (IsLikeRdsS3(resource.Type.DisplayName) && resource.ResourceTypeOptionId != null)
{
@@ -451,7 +461,7 @@ namespace Coscine.Database.Models
resourceTypeOptionObject == null ? new JObject() : JObject.FromObject(resourceTypeOptionObject),
resource.ApplicationProfile,
JToken.Parse(resource.FixedValues ?? "{}"),
- (resource.Creator != null) ? resource.Creator : null,
+ resource.Creator,
resource.Archived == "1"
);
}
@@ -549,4 +559,4 @@ namespace Coscine.Database.Models
return compare == "rdss3" || compare == "rdss3ude";
}
}
-}
+}
\ No newline at end of file