Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Register
Sign in
Toggle navigation
Menu
UPSMF
UPHRH-lms-service
Commits
9e6e616b
Unverified
Commit
9e6e616b
authored
2 years ago
by
Reshmi V Nair
Committed by
GitHub
2 years ago
Browse files
Options
Download
Plain Diff
Merge pull request #500 from BharathwajShankar/merge-5.0.1
Merge 5.0.1
parents
2fd5ad0a
c0facf0e
master
bootcamp
helmchart
release-5.1.0
release-5.2.0
release-5.2.1
release-5.3.0
release-5.3.1
release-5.4.0
release-5.3.1_RC1
release-5.3.0_RC1
release-5.2.0_RC2
release-5.2.0_RC1
release-5.1.0_RC2
release-5.1.0_RC1
No related merge requests found
Changes
29
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
course-mw/course-actors-common/src/main/java/org/sunbird/learner/actors/certificate/service/CourseBatchCertificateActor.java
+28
-7
...tors/certificate/service/CourseBatchCertificateActor.java
course-mw/course-actors-common/src/main/java/org/sunbird/learner/actors/qrcodedownload/QRCodeDownloadManagementActor.java
+9
-13
.../actors/qrcodedownload/QRCodeDownloadManagementActor.java
course-mw/course-actors/src/main/java/org/sunbird/learner/actors/bulkupload/BulkUploadManagementActor.java
+3
-5
.../learner/actors/bulkupload/BulkUploadManagementActor.java
course-mw/sunbird-util/sunbird-platform-core/common-util/pom.xml
+1
-1
...mw/sunbird-util/sunbird-platform-core/common-util/pom.xml
course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/models/util/JsonKey.java
+4
-2
...src/main/java/org/sunbird/common/models/util/JsonKey.java
course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/models/util/aws/AwsCloudService.java
+0
-38
...a/org/sunbird/common/models/util/aws/AwsCloudService.java
course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/models/util/aws/AwsConnectionManager.java
+0
-46
.../sunbird/common/models/util/aws/AwsConnectionManager.java
course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/models/util/aws/AwsFileUtility.java
+0
-37
...va/org/sunbird/common/models/util/aws/AwsFileUtility.java
course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/models/util/azure/AzureCloudService.java
+0
-39
...g/sunbird/common/models/util/azure/AzureCloudService.java
course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/models/util/azure/AzureConnectionManager.java
+0
-130
...bird/common/models/util/azure/AzureConnectionManager.java
course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/models/util/azure/AzureFileUtility.java
+0
-234
...rg/sunbird/common/models/util/azure/AzureFileUtility.java
course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/models/util/azure/package-info.java
+0
-3
...va/org/sunbird/common/models/util/azure/package-info.java
course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/models/util/cloud/CloudService.java
+0
-20
...va/org/sunbird/common/models/util/cloud/CloudService.java
course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/models/util/cloud/CloudServiceFactory.java
+0
-63
...sunbird/common/models/util/cloud/CloudServiceFactory.java
course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/models/util/cloud/CloudUtils.java
+0
-40
...java/org/sunbird/common/models/util/cloud/CloudUtils.java
course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/models/util/gcloud/GcpCloudConnectionManager.java
+0
-46
.../common/models/util/gcloud/GcpCloudConnectionManager.java
course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/models/util/gcloud/GcpCloudService.java
+0
-38
...rg/sunbird/common/models/util/gcloud/GcpCloudService.java
course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/models/util/gcloud/GcpFileUtility.java
+0
-38
...org/sunbird/common/models/util/gcloud/GcpFileUtility.java
course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/util/CloudStorageUtil.java
+20
-70
...c/main/java/org/sunbird/common/util/CloudStorageUtil.java
course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/resources/externalresource.properties
+3
-1
...ommon-util/src/main/resources/externalresource.properties
with
68 additions
and
871 deletions
+68
-871
course-mw/course-actors-common/src/main/java/org/sunbird/learner/actors/certificate/service/CourseBatchCertificateActor.java
+
28
−
7
View file @
9e6e616b
...
@@ -14,8 +14,6 @@ import org.sunbird.actor.base.BaseActor;
...
@@ -14,8 +14,6 @@ import org.sunbird.actor.base.BaseActor;
import
org.sunbird.common.exception.ProjectCommonException
;
import
org.sunbird.common.exception.ProjectCommonException
;
import
org.sunbird.common.models.response.Response
;
import
org.sunbird.common.models.response.Response
;
import
org.sunbird.common.models.util.JsonKey
;
import
org.sunbird.common.models.util.JsonKey
;
import
org.sunbird.common.models.util.LoggerUtil
;
import
org.sunbird.common.models.util.ProjectLogger
;
import
org.sunbird.common.models.util.TelemetryEnvKey
;
import
org.sunbird.common.models.util.TelemetryEnvKey
;
import
org.sunbird.common.request.Request
;
import
org.sunbird.common.request.Request
;
import
org.sunbird.common.request.RequestContext
;
import
org.sunbird.common.request.RequestContext
;
...
@@ -26,6 +24,10 @@ import org.sunbird.learner.constants.CourseJsonKey;
...
@@ -26,6 +24,10 @@ import org.sunbird.learner.constants.CourseJsonKey;
import
org.sunbird.learner.util.CourseBatchUtil
;
import
org.sunbird.learner.util.CourseBatchUtil
;
import
org.sunbird.learner.util.Util
;
import
org.sunbird.learner.util.Util
;
import
static
org
.
sunbird
.
common
.
models
.
util
.
JsonKey
.
CLOUD_STORE_BASE_PATH
;
import
static
org
.
sunbird
.
common
.
models
.
util
.
JsonKey
.
CLOUD_STORE_BASE_PATH_PLACEHOLDER
;
import
static
org
.
sunbird
.
common
.
models
.
util
.
ProjectUtil
.
getConfigValue
;
public
class
CourseBatchCertificateActor
extends
BaseActor
{
public
class
CourseBatchCertificateActor
extends
BaseActor
{
private
CourseBatchDao
courseBatchDao
=
new
CourseBatchDaoImpl
();
private
CourseBatchDao
courseBatchDao
=
new
CourseBatchDaoImpl
();
...
@@ -100,7 +102,8 @@ public class CourseBatchCertificateActor extends BaseActor {
...
@@ -100,7 +102,8 @@ public class CourseBatchCertificateActor extends BaseActor {
String
certName
=
(
String
)
templateData
.
getOrDefault
(
JsonKey
.
TITLE
,
(
String
)
templateDetails
.
getOrDefault
(
JsonKey
.
NAME
,
""
));
String
certName
=
(
String
)
templateData
.
getOrDefault
(
JsonKey
.
TITLE
,
(
String
)
templateDetails
.
getOrDefault
(
JsonKey
.
NAME
,
""
));
template
.
put
(
JsonKey
.
NAME
,
certName
);
template
.
put
(
JsonKey
.
NAME
,
certName
);
template
.
put
(
JsonKey
.
URL
,
templateDetails
.
getOrDefault
(
"artifactUrl"
,
""
));
String
templateUrl
=
getPlaceholderUrl
(
templateDetails
,
"artifactUrl"
);
template
.
put
(
JsonKey
.
URL
,
templateUrl
);
template
.
put
(
JsonKey
.
CRITERIA
,
mapper
.
writeValueAsString
(
template
.
get
(
JsonKey
.
CRITERIA
)));
template
.
put
(
JsonKey
.
CRITERIA
,
mapper
.
writeValueAsString
(
template
.
get
(
JsonKey
.
CRITERIA
)));
if
(
null
!=
template
.
get
(
CourseJsonKey
.
ISSUER
))
{
if
(
null
!=
template
.
get
(
CourseJsonKey
.
ISSUER
))
{
template
.
put
(
template
.
put
(
...
@@ -118,9 +121,13 @@ public class CourseBatchCertificateActor extends BaseActor {
...
@@ -118,9 +121,13 @@ public class CourseBatchCertificateActor extends BaseActor {
CourseJsonKey
.
ISSUER
,
mapper
.
writeValueAsString
(
templateDetails
.
get
(
CourseJsonKey
.
SIGNATORY_LIST
)));
CourseJsonKey
.
ISSUER
,
mapper
.
writeValueAsString
(
templateDetails
.
get
(
CourseJsonKey
.
SIGNATORY_LIST
)));
}
}
if
(
MapUtils
.
isNotEmpty
((
Map
<
String
,
Object
>)
template
.
get
(
CourseJsonKey
.
NOTIFY_TEMPLATE
)))
{
if
(
MapUtils
.
isNotEmpty
((
Map
<
String
,
Object
>)
template
.
get
(
CourseJsonKey
.
NOTIFY_TEMPLATE
)))
{
// We need to change stateImgUrl in notifyTemplate
Map
<
String
,
Object
>
notifyData
=
(
Map
<
String
,
Object
>)
template
.
get
(
CourseJsonKey
.
NOTIFY_TEMPLATE
);
String
notifyTemplateUrl
=
getPlaceholderUrl
(
notifyData
,
JsonKey
.
stateImgUrl
);
notifyData
.
replace
(
JsonKey
.
stateImgUrl
,
notifyTemplateUrl
);
template
.
put
(
template
.
put
(
CourseJsonKey
.
NOTIFY_TEMPLATE
,
CourseJsonKey
.
NOTIFY_TEMPLATE
,
mapper
.
writeValueAsString
(
template
.
get
(
CourseJsonKey
.
NOTIFY_TEMPLATE
)
));
mapper
.
writeValueAsString
(
notifyData
));
}
}
if
(
MapUtils
.
isNotEmpty
((
Map
<
String
,
Object
>)
template
.
get
(
CourseJsonKey
.
ADDITIONAL_PROPS
)))
{
if
(
MapUtils
.
isNotEmpty
((
Map
<
String
,
Object
>)
template
.
get
(
CourseJsonKey
.
ADDITIONAL_PROPS
)))
{
template
.
put
(
template
.
put
(
...
@@ -134,6 +141,17 @@ public class CourseBatchCertificateActor extends BaseActor {
...
@@ -134,6 +141,17 @@ public class CourseBatchCertificateActor extends BaseActor {
}
}
}
}
private
String
getPlaceholderUrl
(
Map
<
String
,
Object
>
templateDetails
,
String
key
)
{
String
templateUrl
=
""
;
if
(
MapUtils
.
isNotEmpty
(
templateDetails
)
&&
templateDetails
.
containsKey
(
key
))
{
// replace the actual cloud url with the template value
templateUrl
=
(
String
)
templateDetails
.
get
(
key
);
if
(
templateUrl
.
contains
(
getConfigValue
(
CLOUD_STORE_BASE_PATH
)))
templateUrl
=
templateUrl
.
replace
(
getConfigValue
(
CLOUD_STORE_BASE_PATH
),
getConfigValue
(
CLOUD_STORE_BASE_PATH_PLACEHOLDER
));
}
return
templateUrl
;
}
private
Map
<
String
,
Object
>
mapESFieldsToObject
(
Map
<
String
,
Object
>
courseBatch
)
{
private
Map
<
String
,
Object
>
mapESFieldsToObject
(
Map
<
String
,
Object
>
courseBatch
)
{
Map
<
String
,
Map
<
String
,
Object
>>
certificateTemplates
=
Map
<
String
,
Map
<
String
,
Object
>>
certificateTemplates
=
(
Map
<
String
,
Map
<
String
,
Object
>>)
(
Map
<
String
,
Map
<
String
,
Object
>>)
...
@@ -174,11 +192,14 @@ public class CourseBatchCertificateActor extends BaseActor {
...
@@ -174,11 +192,14 @@ public class CourseBatchCertificateActor extends BaseActor {
new
TypeReference
<
HashMap
<
String
,
Object
>>()
{
new
TypeReference
<
HashMap
<
String
,
Object
>>()
{
}));
}));
}
}
if
(
StringUtils
.
isNotEmpty
((
String
)
template
.
get
(
CourseJsonKey
.
NOTIFY_TEMPLATE
)))
{
if
(
StringUtils
.
isNotEmpty
((
String
)
template
.
get
(
CourseJsonKey
.
NOTIFY_TEMPLATE
)))
{
String
notifyTemplateData
=
(
String
)
template
.
get
(
CourseJsonKey
.
NOTIFY_TEMPLATE
);
//Modify the placeholder with the actual configured cloud base path as ES should have the actual cloud path
if
(
notifyTemplateData
.
contains
(
getConfigValue
(
CLOUD_STORE_BASE_PATH_PLACEHOLDER
)))
notifyTemplateData
=
notifyTemplateData
.
replace
(
getConfigValue
(
CLOUD_STORE_BASE_PATH_PLACEHOLDER
),
getConfigValue
(
CLOUD_STORE_BASE_PATH
));
template
.
put
(
template
.
put
(
CourseJsonKey
.
NOTIFY_TEMPLATE
,
CourseJsonKey
.
NOTIFY_TEMPLATE
,
mapper
.
readValue
(
mapper
.
readValue
(
notifyTemplateData
,
(
String
)
template
.
get
(
CourseJsonKey
.
NOTIFY_TEMPLATE
),
new
TypeReference
<
HashMap
<
String
,
Object
>>()
{
new
TypeReference
<
HashMap
<
String
,
Object
>>()
{
}));
}));
}
}
...
...
This diff is collapsed.
Click to expand it.
course-mw/course-actors-common/src/main/java/org/sunbird/learner/actors/qrcodedownload/QRCodeDownloadManagementActor.java
+
9
−
13
View file @
9e6e616b
...
@@ -19,8 +19,6 @@ import org.sunbird.cassandra.CassandraOperation;
...
@@ -19,8 +19,6 @@ import org.sunbird.cassandra.CassandraOperation;
import
org.sunbird.common.exception.ProjectCommonException
;
import
org.sunbird.common.exception.ProjectCommonException
;
import
org.sunbird.common.models.response.Response
;
import
org.sunbird.common.models.response.Response
;
import
org.sunbird.common.models.util.JsonKey
;
import
org.sunbird.common.models.util.JsonKey
;
import
org.sunbird.common.models.util.LoggerUtil
;
import
org.sunbird.common.models.util.ProjectLogger
;
import
org.sunbird.common.models.util.ProjectUtil
;
import
org.sunbird.common.models.util.ProjectUtil
;
import
org.sunbird.common.models.util.TelemetryEnvKey
;
import
org.sunbird.common.models.util.TelemetryEnvKey
;
import
org.sunbird.common.request.Request
;
import
org.sunbird.common.request.Request
;
...
@@ -234,7 +232,12 @@ public class QRCodeDownloadManagementActor extends BaseActor {
...
@@ -234,7 +232,12 @@ public class QRCodeDownloadManagementActor extends BaseActor {
if
(
null
!=
obj
&&
obj
instanceof
List
)
{
if
(
null
!=
obj
&&
obj
instanceof
List
)
{
List
<
Map
<
String
,
Object
>>
listOfMap
=
(
List
<
Map
<
String
,
Object
>>)
obj
;
List
<
Map
<
String
,
Object
>>
listOfMap
=
(
List
<
Map
<
String
,
Object
>>)
obj
;
if
(
CollectionUtils
.
isNotEmpty
(
listOfMap
))
{
if
(
CollectionUtils
.
isNotEmpty
(
listOfMap
))
{
return
(
String
)
listOfMap
.
get
(
0
).
get
(
"url"
);
//TODO Resolve it and store. Assuming dial code db will have the template url with data migration script
String
templateUrl
=
(
String
)
listOfMap
.
get
(
0
).
get
(
"url"
);
//replace template url with the actual cloud url
if
(
templateUrl
.
contains
(
getConfigValue
(
CLOUD_STORE_BASE_PATH_PLACEHOLDER
)))
templateUrl
=
templateUrl
.
replace
(
getConfigValue
(
CLOUD_STORE_BASE_PATH_PLACEHOLDER
),
getConfigValue
(
CLOUD_STORE_BASE_PATH
));
return
templateUrl
;
}
}
}
}
}
}
...
@@ -263,22 +266,15 @@ public class QRCodeDownloadManagementActor extends BaseActor {
...
@@ -263,22 +266,15 @@ public class QRCodeDownloadManagementActor extends BaseActor {
objectKey
+=
file
.
getName
();
objectKey
+=
file
.
getName
();
//CSP related changes
//CSP related changes
String
cloudStorage
=
getConfigValue
(
CONTENT_CLOUD_STORAGE_TYPE
);
String
cloudStorage
=
getConfigValue
(
CONTENT_CLOUD_STORAGE_TYPE
);
CloudStorageUtil
.
CloudStorageType
storageType
;
if
(
cloudStorage
==
null
)
{
if
(
cloudStorage
.
equalsIgnoreCase
(
AWS_STR
))
{
storageType
=
CloudStorageUtil
.
CloudStorageType
.
AWS
;
}
else
if
(
cloudStorage
.
equalsIgnoreCase
(
GCLOUD_STR
))
{
storageType
=
CloudStorageUtil
.
CloudStorageType
.
GCLOUD
;
}
else
if
(
cloudStorage
.
equalsIgnoreCase
(
AZURE_STR
))
{
storageType
=
CloudStorageUtil
.
CloudStorageType
.
AZURE
;
}
else
{
ProjectCommonException
.
throwClientErrorException
(
ProjectCommonException
.
throwClientErrorException
(
ResponseCode
.
errorUnsupportedCloudStorage
,
ResponseCode
.
errorUnsupportedCloudStorage
,
ProjectUtil
.
formatMessage
(
ProjectUtil
.
formatMessage
(
ResponseCode
.
errorUnsupportedCloudStorage
.
getErrorMessage
()
,
cloudStorage
));
ResponseCode
.
errorUnsupportedCloudStorage
.
getErrorMessage
()));
return
null
;
return
null
;
}
}
String
fileUrl
=
String
fileUrl
=
CloudStorageUtil
.
upload
(
s
torage
Type
,
CloudStorageUtil
.
upload
(
cloudS
torage
,
getConfigValue
(
CONTENT_CLOUD_STORAGE_CONTAINER
),
getConfigValue
(
CONTENT_CLOUD_STORAGE_CONTAINER
),
objectKey
,
objectKey
,
file
.
getAbsolutePath
());
file
.
getAbsolutePath
());
...
...
This diff is collapsed.
Click to expand it.
course-mw/course-actors/src/main/java/org/sunbird/learner/actors/bulkupload/BulkUploadManagementActor.java
+
3
−
5
View file @
9e6e616b
...
@@ -8,7 +8,6 @@ import org.sunbird.common.models.response.Response;
...
@@ -8,7 +8,6 @@ import org.sunbird.common.models.response.Response;
import
org.sunbird.common.models.util.ActorOperations
;
import
org.sunbird.common.models.util.ActorOperations
;
import
org.sunbird.common.models.util.BulkUploadJsonKey
;
import
org.sunbird.common.models.util.BulkUploadJsonKey
;
import
org.sunbird.common.models.util.JsonKey
;
import
org.sunbird.common.models.util.JsonKey
;
import
org.sunbird.common.models.util.LoggerUtil
;
import
org.sunbird.common.models.util.ProjectUtil
;
import
org.sunbird.common.models.util.ProjectUtil
;
import
org.sunbird.common.models.util.PropertiesCache
;
import
org.sunbird.common.models.util.PropertiesCache
;
import
org.sunbird.common.models.util.TelemetryEnvKey
;
import
org.sunbird.common.models.util.TelemetryEnvKey
;
...
@@ -16,7 +15,6 @@ import org.sunbird.common.request.Request;
...
@@ -16,7 +15,6 @@ import org.sunbird.common.request.Request;
import
org.sunbird.common.request.RequestContext
;
import
org.sunbird.common.request.RequestContext
;
import
org.sunbird.common.responsecode.ResponseCode
;
import
org.sunbird.common.responsecode.ResponseCode
;
import
org.sunbird.common.util.CloudStorageUtil
;
import
org.sunbird.common.util.CloudStorageUtil
;
import
org.sunbird.common.util.CloudStorageUtil.CloudStorageType
;
import
org.sunbird.helper.ServiceFactory
;
import
org.sunbird.helper.ServiceFactory
;
import
org.sunbird.learner.actors.bulkupload.dao.impl.BulkUploadProcessDaoImpl
;
import
org.sunbird.learner.actors.bulkupload.dao.impl.BulkUploadProcessDaoImpl
;
import
org.sunbird.learner.actors.bulkupload.model.BulkUploadProcess
;
import
org.sunbird.learner.actors.bulkupload.model.BulkUploadProcess
;
...
@@ -74,8 +72,8 @@ public class BulkUploadManagementActor extends BaseBulkUploadActor {
...
@@ -74,8 +72,8 @@ public class BulkUploadManagementActor extends BaseBulkUploadActor {
private
void
getBulkUploadDownloadStatusLink
(
Request
actorMessage
)
{
private
void
getBulkUploadDownloadStatusLink
(
Request
actorMessage
)
{
String
processId
=
(
String
)
actorMessage
.
getRequest
().
get
(
JsonKey
.
PROCESS_ID
);
String
processId
=
(
String
)
actorMessage
.
getRequest
().
get
(
JsonKey
.
PROCESS_ID
);
BulkUploadProcessDaoImpl
bulk
u
ploadDao
=
new
BulkUploadProcessDaoImpl
();
BulkUploadProcessDaoImpl
bulk
U
ploadDao
=
new
BulkUploadProcessDaoImpl
();
BulkUploadProcess
bulkUploadProcess
=
bulk
u
ploadDao
.
read
(
actorMessage
.
getRequestContext
(),
processId
);
BulkUploadProcess
bulkUploadProcess
=
bulk
U
ploadDao
.
read
(
actorMessage
.
getRequestContext
(),
processId
);
if
(
bulkUploadProcess
!=
null
)
{
if
(
bulkUploadProcess
!=
null
)
{
try
{
try
{
...
@@ -86,7 +84,7 @@ public class BulkUploadManagementActor extends BaseBulkUploadActor {
...
@@ -86,7 +84,7 @@ public class BulkUploadManagementActor extends BaseBulkUploadActor {
}
}
String
signedUrl
=
String
signedUrl
=
CloudStorageUtil
.
getSignedUrl
(
CloudStorageUtil
.
getSignedUrl
(
CloudStorageType
.
getByName
(
cloudStorageData
.
getStorageType
()
)
,
cloudStorageData
.
getStorageType
(),
cloudStorageData
.
getContainer
(),
cloudStorageData
.
getContainer
(),
cloudStorageData
.
getFileName
());
cloudStorageData
.
getFileName
());
Response
response
=
new
Response
();
Response
response
=
new
Response
();
...
...
This diff is collapsed.
Click to expand it.
course-mw/sunbird-util/sunbird-platform-core/common-util/pom.xml
+
1
−
1
View file @
9e6e616b
...
@@ -219,7 +219,7 @@
...
@@ -219,7 +219,7 @@
<dependency>
<dependency>
<groupId>
org.sunbird
</groupId>
<groupId>
org.sunbird
</groupId>
<artifactId>
cloud-store-sdk
</artifactId>
<artifactId>
cloud-store-sdk
</artifactId>
<version>
1.4.
3
</version>
<version>
1.4.
4
</version>
<exclusions>
<exclusions>
<exclusion>
<exclusion>
<groupId>
com.sun.jersey
</groupId>
<groupId>
com.sun.jersey
</groupId>
...
...
This diff is collapsed.
Click to expand it.
course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/models/util/JsonKey.java
+
4
−
2
View file @
9e6e616b
package
org.sunbird.common.models.util
;
package
org.sunbird.common.models.util
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
/**
/**
...
@@ -789,6 +788,8 @@ public final class JsonKey {
...
@@ -789,6 +788,8 @@ public final class JsonKey {
public
static
final
String
GCLOUD_STR
=
"gcloud"
;
public
static
final
String
GCLOUD_STR
=
"gcloud"
;
public
static
final
String
CLOUD_FOLDER_CONTENT
=
"sunbird_cloud_content_folder"
;
public
static
final
String
CLOUD_FOLDER_CONTENT
=
"sunbird_cloud_content_folder"
;
public
static
final
String
CLOUD_STORE_BASE_PATH
=
"cloud_storage_base_url"
;
public
static
final
String
CLOUD_STORE_BASE_PATH_PLACEHOLDER
=
"cloud_store_base_path_placeholder"
;
public
static
final
String
TO_URL
=
"toUrl"
;
public
static
final
String
TO_URL
=
"toUrl"
;
public
static
final
String
TTL
=
"ttl"
;
public
static
final
String
TTL
=
"ttl"
;
public
static
final
String
TEXTBOOK_TOC_CSV_TTL
=
"sunbird_texbook_toc_csv_ttl"
;
public
static
final
String
TEXTBOOK_TOC_CSV_TTL
=
"sunbird_texbook_toc_csv_ttl"
;
...
@@ -1070,7 +1071,8 @@ public final class JsonKey {
...
@@ -1070,7 +1071,8 @@ public final class JsonKey {
public
static
final
String
OLD_CREATED_DATE
=
"oldCreatedDate"
;
public
static
final
String
OLD_CREATED_DATE
=
"oldCreatedDate"
;
public
static
final
String
X_LOGGING_HEADERS
=
"X_LOGGING_HEADERS"
;
public
static
final
String
X_LOGGING_HEADERS
=
"X_LOGGING_HEADERS"
;
public
static
final
String
LAST_CONTENT_ACCESS_TIME
=
"lastcontentaccesstime"
;
public
static
final
String
LAST_CONTENT_ACCESS_TIME
=
"lastcontentaccesstime"
;
public
static
final
String
GCP
=
"gcloud"
;
public
static
final
String
TEMPLATE_URL
=
"templateUrl"
;
private
JsonKey
()
{}
private
JsonKey
()
{}
}
}
This diff is collapsed.
Click to expand it.
course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/models/util/aws/AwsCloudService.java
deleted
100644 → 0
+
0
−
38
View file @
2fd5ad0a
package
org.sunbird.common.models.util.aws
;
import
org.sunbird.common.models.util.cloud.CloudService
;
import
java.io.File
;
import
java.util.List
;
public
class
AwsCloudService
implements
CloudService
{
@Override
public
String
uploadFile
(
String
containerName
,
String
fileName
,
String
fileLocation
)
{
return
AwsFileUtility
.
uploadFile
(
containerName
,
fileName
,
fileLocation
);
}
@Override
public
boolean
downLoadFile
(
String
containerName
,
String
fileName
,
String
downloadFolder
)
{
return
AwsFileUtility
.
downLoadFile
(
containerName
,
fileName
,
downloadFolder
);
}
@Override
public
String
uploadFile
(
String
containerName
,
File
file
)
{
return
AwsFileUtility
.
uploadFile
(
containerName
,
file
);
}
@Override
public
boolean
deleteFile
(
String
containerName
,
String
fileName
)
{
return
AwsFileUtility
.
deleteFile
(
containerName
,
fileName
);
}
@Override
public
List
<
String
>
listAllFiles
(
String
containerName
)
{
return
AwsFileUtility
.
listAllFiles
(
containerName
);
}
@Override
public
boolean
deleteContainer
(
String
containerName
)
{
return
AwsFileUtility
.
deleteContainer
(
containerName
);
}
}
This diff is collapsed.
Click to expand it.
course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/models/util/aws/AwsConnectionManager.java
deleted
100644 → 0
+
0
−
46
View file @
2fd5ad0a
package
org.sunbird.common.models.util.aws
;
import
org.apache.commons.lang3.StringUtils
;
import
org.sunbird.cloud.storage.BaseStorageService
;
import
org.sunbird.cloud.storage.factory.StorageConfig
;
import
org.sunbird.cloud.storage.factory.StorageServiceFactory
;
import
org.sunbird.common.models.util.JsonKey
;
import
org.sunbird.common.models.util.ProjectLogger
;
import
org.sunbird.common.models.util.PropertiesCache
;
import
static
org
.
sunbird
.
common
.
models
.
util
.
JsonKey
.
AWS_STR
;
public
class
AwsConnectionManager
{
private
static
String
accountName
=
""
;
private
static
String
accountKey
=
""
;
private
static
AwsConnectionManager
connectionManager
;
private
static
BaseStorageService
baseStorageService
;
static
{
String
name
=
System
.
getenv
(
JsonKey
.
ACCOUNT_NAME
);
String
key
=
System
.
getenv
(
JsonKey
.
ACCOUNT_KEY
);
if
(
StringUtils
.
isBlank
(
name
)
||
StringUtils
.
isBlank
(
key
))
{
ProjectLogger
.
log
(
"Aws account name and key is not provided by environment variable."
+
name
+
" "
+
key
);
accountName
=
PropertiesCache
.
getInstance
().
getProperty
(
JsonKey
.
ACCOUNT_NAME
);
accountKey
=
PropertiesCache
.
getInstance
().
getProperty
(
JsonKey
.
ACCOUNT_KEY
);
}
else
{
accountName
=
name
;
accountKey
=
key
;
ProjectLogger
.
log
(
"Aws account name and key is provided by environment variable."
+
name
+
" "
+
key
);
}
}
private
AwsConnectionManager
()
throws
CloneNotSupportedException
{
if
(
connectionManager
!=
null
)
throw
new
CloneNotSupportedException
();
}
public
static
BaseStorageService
getStorageService
(){
if
(
null
==
baseStorageService
){
baseStorageService
=
StorageServiceFactory
.
getStorageService
(
new
StorageConfig
(
AWS_STR
,
accountName
,
accountKey
));
ProjectLogger
.
log
(
"Aws account storage service with account name and key as "
+
accountName
+
" "
+
accountKey
);
}
return
baseStorageService
;
}
}
This diff is collapsed.
Click to expand it.
course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/models/util/aws/AwsFileUtility.java
deleted
100644 → 0
+
0
−
37
View file @
2fd5ad0a
package
org.sunbird.common.models.util.aws
;
import
scala.Option
;
import
java.io.File
;
import
java.util.List
;
import
static
org
.
sunbird
.
common
.
models
.
util
.
cloud
.
CloudUtils
.
getObjectKey
;
public
class
AwsFileUtility
{
public
static
String
uploadFile
(
String
containerName
,
String
fileName
,
String
fileLocation
)
{
String
objectKey
=
getObjectKey
(
containerName
,
fileName
);
return
AwsConnectionManager
.
getStorageService
().
upload
(
containerName
,
fileLocation
+
fileName
,
objectKey
,
Option
.
apply
(
false
),
Option
.
apply
(
1
),
Option
.
apply
(
3
),
Option
.
empty
());
}
public
static
boolean
downLoadFile
(
String
containerName
,
String
fileName
,
String
downloadFolder
)
{
return
false
;
}
public
static
String
uploadFile
(
String
containerName
,
File
file
)
{
String
objectKey
=
getObjectKey
(
containerName
,
file
.
getName
());
return
AwsConnectionManager
.
getStorageService
().
upload
(
containerName
,
file
.
getAbsolutePath
(),
objectKey
,
Option
.
apply
(
false
),
Option
.
apply
(
1
),
Option
.
apply
(
3
),
Option
.
empty
());
}
public
static
boolean
deleteFile
(
String
containerName
,
String
fileName
)
{
return
false
;
}
public
static
List
<
String
>
listAllFiles
(
String
containerName
)
{
return
null
;
}
public
static
boolean
deleteContainer
(
String
containerName
)
{
return
false
;
}
}
This diff is collapsed.
Click to expand it.
course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/models/util/azure/AzureCloudService.java
deleted
100644 → 0
+
0
−
39
View file @
2fd5ad0a
package
org.sunbird.common.models.util.azure
;
import
org.sunbird.common.models.util.cloud.CloudService
;
import
java.io.File
;
import
java.util.List
;
/** Created by arvind on 24/8/17. */
public
class
AzureCloudService
implements
CloudService
{
@Override
public
String
uploadFile
(
String
containerName
,
String
fileName
,
String
fileLocation
)
{
return
AzureFileUtility
.
uploadFile
(
containerName
,
fileName
,
fileLocation
);
}
@Override
public
boolean
downLoadFile
(
String
containerName
,
String
fileName
,
String
downloadFolder
)
{
return
AzureFileUtility
.
downloadFile
(
containerName
,
fileName
,
downloadFolder
);
}
@Override
public
String
uploadFile
(
String
containerName
,
File
file
)
{
return
AzureFileUtility
.
uploadFile
(
containerName
,
file
);
}
@Override
public
boolean
deleteFile
(
String
containerName
,
String
fileName
)
{
return
AzureFileUtility
.
deleteFile
(
containerName
,
fileName
);
}
@Override
public
List
<
String
>
listAllFiles
(
String
containerName
)
{
return
AzureFileUtility
.
listAllBlobbs
(
containerName
);
}
@Override
public
boolean
deleteContainer
(
String
containerName
)
{
return
AzureFileUtility
.
deleteContainer
(
containerName
);
}
}
This diff is collapsed.
Click to expand it.
course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/models/util/azure/AzureConnectionManager.java
deleted
100644 → 0
+
0
−
130
View file @
2fd5ad0a
/** */
package
org.sunbird.common.models.util.azure
;
import
com.microsoft.azure.storage.CloudStorageAccount
;
import
com.microsoft.azure.storage.StorageException
;
import
com.microsoft.azure.storage.blob.BlobContainerPermissions
;
import
com.microsoft.azure.storage.blob.BlobContainerPublicAccessType
;
import
com.microsoft.azure.storage.blob.CloudBlobClient
;
import
com.microsoft.azure.storage.blob.CloudBlobContainer
;
import
java.net.URISyntaxException
;
import
java.security.InvalidKeyException
;
import
java.util.Locale
;
import
org.apache.commons.lang3.StringUtils
;
import
org.sunbird.common.models.util.JsonKey
;
import
org.sunbird.common.models.util.ProjectLogger
;
import
org.sunbird.common.models.util.PropertiesCache
;
/**
* This class will manage azure connection.
*
* @author Manzarul
*/
public
class
AzureConnectionManager
{
private
static
String
accountName
=
""
;
private
static
String
accountKey
=
""
;
private
static
String
storageAccountString
;
private
static
AzureConnectionManager
connectionManager
;
static
{
String
name
=
System
.
getenv
(
JsonKey
.
ACCOUNT_NAME
);
String
key
=
System
.
getenv
(
JsonKey
.
ACCOUNT_KEY
);
if
(
StringUtils
.
isBlank
(
name
)
||
StringUtils
.
isBlank
(
key
))
{
ProjectLogger
.
log
(
"Azure account name and key is not provided by environment variable."
+
name
+
" "
+
key
);
accountName
=
PropertiesCache
.
getInstance
().
getProperty
(
JsonKey
.
ACCOUNT_NAME
);
accountKey
=
PropertiesCache
.
getInstance
().
getProperty
(
JsonKey
.
ACCOUNT_KEY
);
storageAccountString
=
"DefaultEndpointsProtocol=https;AccountName="
+
accountName
+
";AccountKey="
+
accountKey
+
";EndpointSuffix=core.windows.net"
;
}
else
{
accountName
=
name
;
accountKey
=
key
;
ProjectLogger
.
log
(
"Azure account name and key is provided by environment variable."
+
name
+
" "
+
key
);
storageAccountString
=
"DefaultEndpointsProtocol=https;AccountName="
+
accountName
+
";AccountKey="
+
accountKey
+
";EndpointSuffix=core.windows.net"
;
}
}
private
AzureConnectionManager
()
throws
CloneNotSupportedException
{
if
(
connectionManager
!=
null
)
throw
new
CloneNotSupportedException
();
}
/**
* This method will provide Azure CloudBlobContainer object or in case of error it will provide
* null;
*
* @param containerName String
* @return CloudBlobContainer or null
*/
public
static
CloudBlobContainer
getContainer
(
String
containerName
,
boolean
isPublicAccess
)
{
try
{
CloudBlobClient
cloudBlobClient
=
getBlobClient
();
// Get a reference to a container , The container name must be lower case
CloudBlobContainer
container
=
cloudBlobClient
.
getContainerReference
(
containerName
.
toLowerCase
(
Locale
.
ENGLISH
));
// Create the container if it does not exist.
boolean
response
=
container
.
createIfNotExists
();
ProjectLogger
.
log
(
"container creation done if not exist=="
+
response
);
// Create a permissions object.
if
(
isPublicAccess
)
{
BlobContainerPermissions
containerPermissions
=
new
BlobContainerPermissions
();
// Include public access in the permissions object.
containerPermissions
.
setPublicAccess
(
BlobContainerPublicAccessType
.
CONTAINER
);
// Set the permissions on the container.
container
.
uploadPermissions
(
containerPermissions
);
}
return
container
;
}
catch
(
Exception
e
)
{
ProjectLogger
.
log
(
e
.
getMessage
(),
e
);
}
return
null
;
}
public
static
CloudBlobContainer
getContainerReference
(
String
containerName
)
{
CloudBlobContainer
container
=
null
;
try
{
// Create the blob client.
CloudBlobClient
blobClient
=
getBlobClient
();
// Retrieve reference to a previously created container.
container
=
blobClient
.
getContainerReference
(
containerName
.
toLowerCase
(
Locale
.
ENGLISH
));
if
(
container
.
exists
())
{
return
container
;
}
}
catch
(
URISyntaxException
e
)
{
ProjectLogger
.
log
(
e
.
getMessage
(),
e
);
}
catch
(
StorageException
e
)
{
ProjectLogger
.
log
(
e
.
getMessage
(),
e
);
}
ProjectLogger
.
log
(
"Container does not exist =="
+
containerName
);
return
null
;
}
private
static
CloudBlobClient
getBlobClient
()
{
// Retrieve storage account from connection-string.
CloudStorageAccount
storageAccount
=
null
;
CloudBlobClient
blobClient
=
null
;
try
{
storageAccount
=
CloudStorageAccount
.
parse
(
storageAccountString
);
// Create the blob client.
blobClient
=
storageAccount
.
createCloudBlobClient
();
}
catch
(
URISyntaxException
e
)
{
ProjectLogger
.
log
(
e
.
getMessage
(),
e
);
}
catch
(
InvalidKeyException
e
)
{
ProjectLogger
.
log
(
e
.
getMessage
(),
e
);
}
return
blobClient
;
}
}
This diff is collapsed.
Click to expand it.
course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/models/util/azure/AzureFileUtility.java
deleted
100644 → 0
+
0
−
234
View file @
2fd5ad0a
/** */
package
org.sunbird.common.models.util.azure
;
import
com.microsoft.azure.storage.StorageException
;
import
com.microsoft.azure.storage.blob.CloudBlobContainer
;
import
com.microsoft.azure.storage.blob.CloudBlockBlob
;
import
com.microsoft.azure.storage.blob.ListBlobItem
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.net.URISyntaxException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.tika.Tika
;
import
org.sunbird.common.models.util.LoggerUtil
;
import
org.sunbird.common.models.util.ProjectLogger
;
import
org.sunbird.common.models.util.Slug
;
/** @author Manzarul */
public
class
AzureFileUtility
{
private
static
final
String
DEFAULT_CONTAINER
=
"default"
;
private
static
LoggerUtil
logger
=
new
LoggerUtil
(
Slug
.
class
);
/**
* This method will remove the file from Azure Storage.
*
* @param fileName
* @param containerName
* @return boolean
*/
public
static
boolean
deleteFile
(
String
containerName
,
String
fileName
)
{
if
(
fileName
==
null
)
{
logger
.
info
(
null
,
"File name can not be null"
);
return
false
;
}
if
(
StringUtils
.
isBlank
(
containerName
))
{
logger
.
info
(
null
,
"Container name can't be null or empty"
);
return
false
;
}
CloudBlobContainer
container
=
AzureConnectionManager
.
getContainer
(
containerName
,
true
);
if
(
container
==
null
)
{
logger
.
info
(
null
,
"Unable to get Azure contains object"
);
return
false
;
}
try
{
// Retrieve reference to a blob named "myimage.jpg".
CloudBlockBlob
blob
=
container
.
getBlockBlobReference
(
fileName
);
// Delete the blob.
boolean
response
=
blob
.
deleteIfExists
();
if
(!
response
)
{
logger
.
info
(
null
,
"Provided file not found to delete."
);
}
return
true
;
}
catch
(
Exception
e
)
{
logger
.
error
(
null
,
e
.
getMessage
(),
e
);
}
return
false
;
}
/**
* This method will remove the container from Azure Storage.
*
* @param containerName
* @return boolean
*/
public
static
boolean
deleteContainer
(
String
containerName
)
{
if
(
StringUtils
.
isBlank
(
containerName
))
{
logger
.
info
(
null
,
"Container name can't be null or empty"
);
return
false
;
}
CloudBlobContainer
container
=
AzureConnectionManager
.
getContainer
(
containerName
,
true
);
if
(
container
==
null
)
{
logger
.
info
(
null
,
"Unable to get Azure contains object"
);
return
false
;
}
try
{
boolean
response
=
container
.
deleteIfExists
();
if
(!
response
)
{
logger
.
info
(
null
,
"Container not found.."
);
}
else
{
logger
.
info
(
null
,
"Container is deleted==="
);
}
return
true
;
}
catch
(
Exception
e
)
{
logger
.
error
(
null
,
e
.
getMessage
(),
e
);
}
return
false
;
}
public
static
String
uploadFile
(
String
containerName
,
String
blobName
,
String
fileName
)
{
CloudBlobContainer
container
=
AzureConnectionManager
.
getContainer
(
containerName
,
true
);
// Create or overwrite the "myimage.jpg" blob with contents from a local file.
CloudBlockBlob
blob
=
null
;
String
fileUrl
=
null
;
FileInputStream
fis
=
null
;
Tika
tika
=
new
Tika
();
try
{
blob
=
container
.
getBlockBlobReference
(
blobName
);
File
source
=
new
File
(
fileName
);
fis
=
new
FileInputStream
(
source
);
String
mimeType
=
tika
.
detect
(
source
);
logger
.
info
(
null
,
"File - "
+
source
.
getName
()
+
" mimeType "
+
mimeType
);
blob
.
getProperties
().
setContentType
(
mimeType
);
blob
.
upload
(
fis
,
source
.
length
());
// fileUrl = blob.getStorageUri().getPrimaryUri().getPath();
fileUrl
=
blob
.
getUri
().
toString
();
}
catch
(
URISyntaxException
|
IOException
e
)
{
logger
.
error
(
null
,
"Unable to upload file :"
+
fileName
,
e
);
}
catch
(
Exception
e
)
{
logger
.
error
(
null
,
e
.
getMessage
(),
e
);
}
finally
{
if
(
null
!=
fis
)
{
try
{
fis
.
close
();
}
catch
(
IOException
e
)
{
logger
.
error
(
null
,
e
.
getMessage
(),
e
);
}
}
}
return
fileUrl
;
}
public
static
String
uploadFile
(
String
containerName
,
File
source
)
{
String
containerPath
=
""
;
String
filePath
=
""
;
Tika
tika
=
new
Tika
();
String
contrName
=
containerName
;
if
(
StringUtils
.
isBlank
(
containerName
))
{
contrName
=
DEFAULT_CONTAINER
;
}
else
{
contrName
=
containerName
.
toLowerCase
();
}
if
(
containerName
.
startsWith
(
"/"
))
{
contrName
=
containerName
.
substring
(
1
);
}
if
(
contrName
.
contains
(
"/"
))
{
String
[]
arr
=
contrName
.
split
(
"/"
,
2
);
containerPath
=
arr
[
0
];
if
(
arr
[
1
].
length
()
>
0
&&
arr
[
1
].
endsWith
(
"/"
))
{
filePath
=
arr
[
1
];
}
else
if
(
arr
[
1
].
length
()
>
0
)
{
filePath
=
arr
[
1
]
+
"/"
;
}
}
else
{
containerPath
=
contrName
;
}
CloudBlobContainer
container
=
AzureConnectionManager
.
getContainer
(
containerPath
,
true
);
// Create or overwrite the "myimage.jpg" blob with contents from a local file.
CloudBlockBlob
blob
=
null
;
String
fileUrl
=
null
;
FileInputStream
fis
=
null
;
try
{
blob
=
container
.
getBlockBlobReference
(
filePath
+
source
.
getName
());
// File source = new File(fileName);
fis
=
new
FileInputStream
(
source
);
String
mimeType
=
tika
.
detect
(
source
);
logger
.
info
(
null
,
"File - "
+
source
.
getName
()
+
" mimeType "
+
mimeType
);
blob
.
getProperties
().
setContentType
(
mimeType
);
blob
.
upload
(
fis
,
source
.
length
());
// fileUrl = blob.getStorageUri().getPrimaryUri().getPath();
fileUrl
=
blob
.
getUri
().
toString
();
}
catch
(
URISyntaxException
|
IOException
e
)
{
logger
.
error
(
null
,
"Unable to upload file :"
+
source
.
getName
(),
e
);
}
catch
(
Exception
e
)
{
logger
.
error
(
null
,
e
.
getMessage
(),
e
);
}
finally
{
if
(
null
!=
fis
)
{
try
{
fis
.
close
();
}
catch
(
IOException
e
)
{
logger
.
error
(
null
,
e
.
getMessage
(),
e
);
}
}
}
return
fileUrl
;
}
public
static
boolean
downloadFile
(
String
containerName
,
String
blobName
,
String
downloadFolder
)
{
String
dwnldFolder
=
""
;
boolean
flag
=
false
;
CloudBlobContainer
container
=
AzureConnectionManager
.
getContainer
(
containerName
,
true
);
// Create or overwrite blob with contents .
CloudBlockBlob
blob
=
null
;
FileOutputStream
fos
=
null
;
try
{
blob
=
container
.
getBlockBlobReference
(
blobName
);
if
(
blob
.
exists
())
{
if
(!(
downloadFolder
.
endsWith
((
"/"
))))
{
dwnldFolder
=
downloadFolder
+
"/"
;
}
File
file
=
new
File
(
dwnldFolder
+
blobName
);
fos
=
new
FileOutputStream
(
file
);
blob
.
download
(
fos
);
}
}
catch
(
URISyntaxException
|
StorageException
|
FileNotFoundException
e
)
{
logger
.
error
(
null
,
"Unable to upload blobfile :"
+
blobName
,
e
);
}
catch
(
Exception
e
)
{
logger
.
error
(
null
,
e
.
getMessage
(),
e
);
}
finally
{
if
(
null
!=
fos
)
{
try
{
fos
.
close
();
}
catch
(
IOException
e
)
{
logger
.
error
(
null
,
e
.
getMessage
(),
e
);
}
}
}
return
flag
;
}
public
static
List
<
String
>
listAllBlobbs
(
String
containerName
)
{
List
<
String
>
blobsList
=
new
ArrayList
<>();
CloudBlobContainer
container
=
AzureConnectionManager
.
getContainer
(
containerName
,
true
);
// Loop over blobs within the container and output the URI to each of them.
if
(
container
!=
null
)
{
for
(
ListBlobItem
blobItem
:
container
.
listBlobs
())
{
blobsList
.
add
(
blobItem
.
getUri
().
toString
());
}
}
return
blobsList
;
}
}
This diff is collapsed.
Click to expand it.
course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/models/util/azure/package-info.java
deleted
100644 → 0
+
0
−
3
View file @
2fd5ad0a
/** */
/** @author Manzarul */
package
org.sunbird.common.models.util.azure
;
This diff is collapsed.
Click to expand it.
course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/models/util/cloud/CloudService.java
deleted
100644 → 0
+
0
−
20
View file @
2fd5ad0a
package
org.sunbird.common.models.util.cloud
;
import
java.io.File
;
import
java.util.List
;
/** Created by arvind on 24/8/17. */
public
interface
CloudService
{
String
uploadFile
(
String
containerName
,
String
filName
,
String
fileLocation
);
boolean
downLoadFile
(
String
containerName
,
String
fileName
,
String
downloadFolder
);
String
uploadFile
(
String
containerName
,
File
file
);
boolean
deleteFile
(
String
containerName
,
String
fileName
);
List
<
String
>
listAllFiles
(
String
containerName
);
boolean
deleteContainer
(
String
containerName
);
}
This diff is collapsed.
Click to expand it.
course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/models/util/cloud/CloudServiceFactory.java
deleted
100644 → 0
+
0
−
63
View file @
2fd5ad0a
package
org.sunbird.common.models.util.cloud
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
org.sunbird.common.models.util.ProjectUtil
;
import
org.sunbird.common.models.util.aws.AwsCloudService
;
import
org.sunbird.common.models.util.azure.AzureCloudService
;
import
org.sunbird.common.models.util.gcloud.GcpCloudService
;
import
static
org
.
sunbird
.
common
.
models
.
util
.
JsonKey
.*;
/**
* Factory class to store the various upload download services like Azure , Amazon S3 etc... Created
* by arvind on 24/8/17.
*/
public
class
CloudServiceFactory
{
private
static
Map
<
String
,
CloudService
>
factory
=
new
HashMap
<>();
private
static
List
<
String
>
allowedServiceNames
=
Arrays
.
asList
(
AZURE_STR
,
AWS_STR
,
GCLOUD_STR
);
private
CloudServiceFactory
()
{}
/**
* @param serviceName
* @return
*/
public
static
Object
get
(
String
serviceName
)
{
if
(
ProjectUtil
.
isNotNull
(
factory
.
get
(
serviceName
)))
{
return
factory
.
get
(
serviceName
);
}
else
{
// create the service with the given name
return
createService
(
serviceName
);
}
}
/**
* @param serviceName
* @return
*/
private
static
CloudService
createService
(
String
serviceName
)
{
if
(!(
allowedServiceNames
.
contains
(
serviceName
)))
{
return
null
;
}
synchronized
(
CloudServiceFactory
.
class
)
{
if
(
ProjectUtil
.
isNull
(
factory
.
get
(
serviceName
))
&&
AZURE_STR
.
equalsIgnoreCase
(
serviceName
))
{
CloudService
service
=
new
AzureCloudService
();
factory
.
put
(
AZURE_STR
,
service
);
}
else
if
(
ProjectUtil
.
isNull
(
factory
.
get
(
serviceName
))
&&
AWS_STR
.
equalsIgnoreCase
(
serviceName
))
{
CloudService
service
=
new
AwsCloudService
();
factory
.
put
(
AWS_STR
,
service
);
}
else
if
(
ProjectUtil
.
isNull
(
factory
.
get
(
serviceName
))
&&
GCLOUD_STR
.
equalsIgnoreCase
(
serviceName
))
{
CloudService
service
=
new
GcpCloudService
();
factory
.
put
(
GCLOUD_STR
,
service
);
}
}
return
factory
.
get
(
serviceName
);
}
}
This diff is collapsed.
Click to expand it.
course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/models/util/cloud/CloudUtils.java
deleted
100644 → 0
+
0
−
40
View file @
2fd5ad0a
package
org.sunbird.common.models.util.cloud
;
import
org.apache.commons.lang3.StringUtils
;
import
org.sunbird.common.models.util.ProjectLogger
;
public
class
CloudUtils
{
public
static
String
getObjectKey
(
String
containerName
,
String
fileName
)
{
if
(
containerName
==
null
||
fileName
==
null
)
{
ProjectLogger
.
log
(
"Container or fileName can not be null"
);
return
""
;
}
String
containerPath
=
""
;
String
filePath
=
""
;
String
contrName
=
containerName
;
String
objectKey
=
""
;
if
(
containerName
.
startsWith
(
"/"
))
{
contrName
=
containerName
.
substring
(
1
);
}
if
(
contrName
.
contains
(
"/"
))
{
String
[]
arr
=
contrName
.
split
(
"/"
,
2
);
containerPath
=
arr
[
0
];
if
(
arr
[
1
].
length
()
>
0
&&
arr
[
1
].
endsWith
(
"/"
))
{
filePath
=
arr
[
1
];
}
else
if
(
arr
[
1
].
length
()
>
0
)
{
filePath
=
arr
[
1
]
+
"/"
;
}
}
else
{
containerPath
=
contrName
;
}
if
(
StringUtils
.
isBlank
(
filePath
))
objectKey
=
containerPath
.
endsWith
(
"/"
)
?
containerPath
+
fileName
:
containerPath
+
"/"
+
fileName
;
else
objectKey
=
filePath
+
fileName
;
return
objectKey
;
}
}
This diff is collapsed.
Click to expand it.
course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/models/util/gcloud/GcpCloudConnectionManager.java
deleted
100644 → 0
+
0
−
46
View file @
2fd5ad0a
package
org.sunbird.common.models.util.gcloud
;
import
org.apache.commons.lang3.StringUtils
;
import
org.sunbird.cloud.storage.BaseStorageService
;
import
org.sunbird.cloud.storage.factory.StorageConfig
;
import
org.sunbird.cloud.storage.factory.StorageServiceFactory
;
import
org.sunbird.common.models.util.JsonKey
;
import
org.sunbird.common.models.util.ProjectLogger
;
import
org.sunbird.common.models.util.PropertiesCache
;
import
static
org
.
sunbird
.
common
.
models
.
util
.
JsonKey
.
GCLOUD_STR
;
public
class
GcpCloudConnectionManager
{
private
static
String
accountName
=
""
;
private
static
String
accountKey
=
""
;
private
static
GcpCloudConnectionManager
connectionManager
;
private
static
BaseStorageService
baseStorageService
;
static
{
String
name
=
System
.
getenv
(
JsonKey
.
ACCOUNT_NAME
);
String
key
=
System
.
getenv
(
JsonKey
.
ACCOUNT_KEY
);
if
(
StringUtils
.
isBlank
(
name
)
||
StringUtils
.
isBlank
(
key
))
{
ProjectLogger
.
log
(
"Gcloud account name and key is not provided by environment variable."
+
name
+
" "
+
key
);
accountName
=
PropertiesCache
.
getInstance
().
getProperty
(
JsonKey
.
ACCOUNT_NAME
);
accountKey
=
PropertiesCache
.
getInstance
().
getProperty
(
JsonKey
.
ACCOUNT_KEY
);
}
else
{
accountName
=
name
;
accountKey
=
key
;
ProjectLogger
.
log
(
"Gcloud account name and key is provided by environment variable."
+
name
+
" "
+
key
);
}
}
private
GcpCloudConnectionManager
()
throws
CloneNotSupportedException
{
if
(
connectionManager
!=
null
)
throw
new
CloneNotSupportedException
();
}
public
static
BaseStorageService
getStorageService
(){
if
(
null
==
baseStorageService
){
baseStorageService
=
StorageServiceFactory
.
getStorageService
(
new
StorageConfig
(
GCLOUD_STR
,
accountName
,
accountKey
));
ProjectLogger
.
log
(
"Gcloud account storage service with account name and key as "
+
accountName
+
" "
+
accountKey
);
}
return
baseStorageService
;
}
}
This diff is collapsed.
Click to expand it.
course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/models/util/gcloud/GcpCloudService.java
deleted
100644 → 0
+
0
−
38
View file @
2fd5ad0a
package
org.sunbird.common.models.util.gcloud
;
import
org.sunbird.common.models.util.cloud.CloudService
;
import
java.io.File
;
import
java.util.List
;
public
class
GcpCloudService
implements
CloudService
{
@Override
public
String
uploadFile
(
String
containerName
,
String
fileName
,
String
fileLocation
)
{
return
GcpFileUtility
.
uploadFile
(
containerName
,
fileName
,
fileLocation
);
}
@Override
public
boolean
downLoadFile
(
String
containerName
,
String
fileName
,
String
downloadFolder
)
{
return
GcpFileUtility
.
downLoadFile
(
containerName
,
fileName
,
downloadFolder
);
}
@Override
public
String
uploadFile
(
String
containerName
,
File
file
)
{
return
GcpFileUtility
.
uploadFile
(
containerName
,
file
);
}
@Override
public
boolean
deleteFile
(
String
containerName
,
String
fileName
)
{
return
GcpFileUtility
.
deleteFile
(
containerName
,
fileName
);
}
@Override
public
List
<
String
>
listAllFiles
(
String
containerName
)
{
return
GcpFileUtility
.
listAllFiles
(
containerName
);
}
@Override
public
boolean
deleteContainer
(
String
containerName
)
{
return
GcpFileUtility
.
deleteContainer
(
containerName
);
}
}
This diff is collapsed.
Click to expand it.
course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/models/util/gcloud/GcpFileUtility.java
deleted
100644 → 0
+
0
−
38
View file @
2fd5ad0a
package
org.sunbird.common.models.util.gcloud
;
import
org.sunbird.common.models.util.aws.AwsConnectionManager
;
import
scala.Option
;
import
java.io.File
;
import
java.util.List
;
import
static
org
.
sunbird
.
common
.
models
.
util
.
cloud
.
CloudUtils
.
getObjectKey
;
public
class
GcpFileUtility
{
public
static
String
uploadFile
(
String
containerName
,
String
fileName
,
String
fileLocation
)
{
String
objectKey
=
getObjectKey
(
containerName
,
fileName
);
return
GcpCloudConnectionManager
.
getStorageService
().
upload
(
containerName
,
fileLocation
+
fileName
,
objectKey
,
Option
.
apply
(
false
),
Option
.
apply
(
1
),
Option
.
apply
(
3
),
Option
.
empty
());
}
public
static
boolean
downLoadFile
(
String
containerName
,
String
fileName
,
String
downloadFolder
)
{
return
false
;
}
public
static
String
uploadFile
(
String
containerName
,
File
file
)
{
String
objectKey
=
getObjectKey
(
containerName
,
file
.
getName
());
return
GcpCloudConnectionManager
.
getStorageService
().
upload
(
containerName
,
file
.
getAbsolutePath
(),
objectKey
,
Option
.
apply
(
false
),
Option
.
apply
(
1
),
Option
.
apply
(
3
),
Option
.
empty
());
}
public
static
boolean
deleteFile
(
String
containerName
,
String
fileName
)
{
return
false
;
}
public
static
List
<
String
>
listAllFiles
(
String
containerName
)
{
return
null
;
}
public
static
boolean
deleteContainer
(
String
containerName
)
{
return
false
;
}
}
This diff is collapsed.
Click to expand it.
course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/util/CloudStorageUtil.java
+
20
−
70
View file @
9e6e616b
...
@@ -2,60 +2,24 @@ package org.sunbird.common.util;
...
@@ -2,60 +2,24 @@ package org.sunbird.common.util;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
import
org.sunbird.cloud.storage.
I
StorageService
;
import
org.sunbird.cloud.storage.
Base
StorageService
;
import
org.sunbird.cloud.storage.factory.StorageConfig
;
import
org.sunbird.cloud.storage.factory.StorageConfig
;
import
org.sunbird.cloud.storage.factory.StorageServiceFactory
;
import
org.sunbird.cloud.storage.factory.StorageServiceFactory
;
import
org.sunbird.common.exception.ProjectCommonException
;
import
org.sunbird.common.models.util.JsonKey
;
import
org.sunbird.common.models.util.JsonKey
;
import
org.sunbird.common.models.util.ProjectUtil
;
import
org.sunbird.common.models.util.ProjectUtil
;
import
org.sunbird.common.models.util.PropertiesCache
;
import
org.sunbird.common.models.util.PropertiesCache
;
import
org.sunbird.common.responsecode.ResponseCode
;
import
scala.Option
;
import
scala.Option
;
import
scala.Some
;
import
scala.Some
;
import
static
org
.
sunbird
.
common
.
models
.
util
.
JsonKey
.*;
public
class
CloudStorageUtil
{
public
class
CloudStorageUtil
{
private
static
final
int
STORAGE_SERVICE_API_RETRY_COUNT
=
3
;
private
static
final
int
STORAGE_SERVICE_API_RETRY_COUNT
=
3
;
private
static
final
Map
<
String
,
IStorageService
>
storageServiceMap
=
new
HashMap
<>();
private
static
final
Map
<
String
,
BaseStorageService
>
storageServiceMap
=
new
HashMap
<>();
public
enum
CloudStorageType
{
AZURE
(
AZURE_STR
),
AWS
(
AWS_STR
),
GCLOUD
(
GCLOUD_STR
);
private
String
type
;
private
CloudStorageType
(
String
type
)
{
this
.
type
=
type
;
}
public
String
getType
()
{
return
this
.
type
;
}
public
static
CloudStorageType
getByName
(
String
type
)
{
if
(
AZURE
.
type
.
equalsIgnoreCase
(
type
))
{
return
CloudStorageType
.
AZURE
;
}
if
(
AWS
.
type
.
equalsIgnoreCase
(
type
))
{
return
CloudStorageType
.
AWS
;
}
if
(
GCLOUD
.
type
.
equalsIgnoreCase
(
type
))
{
return
CloudStorageType
.
GCLOUD
;
}
else
{
ProjectCommonException
.
throwClientErrorException
(
ResponseCode
.
errorUnsupportedCloudStorage
,
ProjectUtil
.
formatMessage
(
ResponseCode
.
errorUnsupportedCloudStorage
.
getErrorMessage
(),
type
));
return
null
;
}
}
}
public
static
String
upload
(
public
static
String
upload
(
CloudStorageType
storageType
,
String
container
,
String
objectKey
,
String
filePath
)
{
String
storageType
,
String
container
,
String
objectKey
,
String
filePath
)
{
I
StorageService
storageService
=
getStorageService
(
storageType
);
Base
StorageService
storageService
=
getStorageService
(
storageType
);
return
storageService
.
upload
(
return
storageService
.
upload
(
container
,
container
,
...
@@ -68,49 +32,35 @@ public class CloudStorageUtil {
...
@@ -68,49 +32,35 @@ public class CloudStorageUtil {
}
}
public
static
String
getSignedUrl
(
public
static
String
getSignedUrl
(
CloudStorageType
storageType
,
String
container
,
String
objectKey
)
{
String
storageType
,
String
container
,
String
objectKey
)
{
IStorageService
storageService
=
getStorageService
(
storageType
);
BaseStorageService
storageService
=
getStorageService
(
storageType
);
return
getSignedUrl
(
storageService
,
storageType
,
container
,
objectKey
);
return
getSignedUrl
(
storageService
,
container
,
objectKey
,
storageType
);
}
public
static
String
getAnalyticsSignedUrl
(
CloudStorageType
storageType
,
String
container
,
String
objectKey
)
{
IStorageService
analyticsStorageService
=
getAnalyticsStorageService
(
storageType
);
return
getSignedUrl
(
analyticsStorageService
,
storageType
,
container
,
objectKey
);
}
}
public
static
String
getSignedUrl
(
public
static
String
getSignedUrl
(
IStorageService
storageService
,
BaseStorageService
storageService
,
CloudStorageType
storageType
,
String
container
,
String
container
,
String
objectKey
,
String
cloudType
)
{
String
objectKey
)
{
return
storageService
.
getSignedURLV2
(
container
,
objectKey
,
Some
.
apply
(
getTimeoutInSeconds
()),
int
timeoutInSeconds
=
getTimeoutInSeconds
();
Some
.
apply
(
"r"
),
Some
.
apply
(
"application/pdf"
));
return
storageService
.
getSignedURL
(
container
,
objectKey
,
Some
.
apply
(
timeoutInSeconds
),
Some
.
apply
(
"r"
));
}
}
private
static
I
StorageService
getStorageService
(
CloudStorageType
storageType
)
{
private
static
Base
StorageService
getStorageService
(
String
storageType
)
{
String
storageKey
=
PropertiesCache
.
getInstance
().
getProperty
(
JsonKey
.
ACCOUNT_NAME
);
String
storageKey
=
PropertiesCache
.
getInstance
().
getProperty
(
JsonKey
.
ACCOUNT_NAME
);
String
storageSecret
=
PropertiesCache
.
getInstance
().
getProperty
(
JsonKey
.
ACCOUNT_KEY
);
String
storageSecret
=
PropertiesCache
.
getInstance
().
getProperty
(
JsonKey
.
ACCOUNT_KEY
);
return
getStorageService
(
storageType
,
storageKey
,
storageSecret
);
return
getStorageService
(
storageType
,
storageKey
,
storageSecret
);
}
}
private
static
IStorageService
getAnalyticsStorageService
(
CloudStorageType
storageType
)
{
private
static
BaseStorageService
getStorageService
(
String
storageKey
=
PropertiesCache
.
getInstance
().
getProperty
(
JsonKey
.
ANALYTICS_ACCOUNT_NAME
);
String
storageType
,
String
storageKey
,
String
storageSecret
)
{
String
storageSecret
=
PropertiesCache
.
getInstance
().
getProperty
(
JsonKey
.
ANALYTICS_ACCOUNT_KEY
);
String
compositeKey
=
storageType
+
"-"
+
storageKey
;
return
getStorageService
(
storageType
,
storageKey
,
storageSecret
);
}
private
static
IStorageService
getStorageService
(
CloudStorageType
storageType
,
String
storageKey
,
String
storageSecret
)
{
String
compositeKey
=
storageType
.
getType
()
+
"-"
+
storageKey
;
if
(
storageServiceMap
.
containsKey
(
compositeKey
))
{
if
(
storageServiceMap
.
containsKey
(
compositeKey
))
{
return
storageServiceMap
.
get
(
compositeKey
);
return
storageServiceMap
.
get
(
compositeKey
);
}
}
synchronized
(
CloudStorageUtil
.
class
)
{
synchronized
(
CloudStorageUtil
.
class
)
{
StorageConfig
storageConfig
=
StorageConfig
storageConfig
=
new
StorageConfig
(
storageType
.
getType
()
,
storageKey
,
storageSecret
);
new
StorageConfig
(
storageType
,
storageKey
,
storageSecret
);
I
StorageService
storageService
=
StorageServiceFactory
.
getStorageService
(
storageConfig
);
Base
StorageService
storageService
=
StorageServiceFactory
.
getStorageService
(
storageConfig
);
storageServiceMap
.
put
(
compositeKey
,
storageService
);
storageServiceMap
.
put
(
compositeKey
,
storageService
);
}
}
return
storageServiceMap
.
get
(
compositeKey
);
return
storageServiceMap
.
get
(
compositeKey
);
...
@@ -122,8 +72,8 @@ public class CloudStorageUtil {
...
@@ -122,8 +72,8 @@ public class CloudStorageUtil {
}
}
public
static
String
getUri
(
public
static
String
getUri
(
CloudStorageType
storageType
,
String
container
,
String
prefix
,
boolean
isDirectory
)
{
String
storageType
,
String
container
,
String
prefix
,
boolean
isDirectory
)
{
I
StorageService
storageService
=
getStorageService
(
storageType
);
Base
StorageService
storageService
=
getStorageService
(
storageType
);
return
storageService
.
getUri
(
container
,
prefix
,
Option
.
apply
(
isDirectory
));
return
storageService
.
getUri
(
container
,
prefix
,
Option
.
apply
(
isDirectory
));
}
}
}
}
This diff is collapsed.
Click to expand it.
course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/resources/externalresource.properties
+
3
−
1
View file @
9e6e616b
...
@@ -205,4 +205,6 @@ kafka_assessment_topic=
...
@@ -205,4 +205,6 @@ kafka_assessment_topic=
sunbird_msg_sender
=
sunbird_msg_sender
=
sunbird_msg_91_auth
=
sunbird_msg_91_auth
=
sunbird_api_mgr_base_url
=
https://dev.sunbirded.org/api
sunbird_api_mgr_base_url
=
https://dev.sunbirded.org/api
enrollment_list_size
=
1000
enrollment_list_size
=
1000
\ No newline at end of file
cloud_storage_base_url
=
https://sunbirddev.blob.core.windows.net
cloud_store_base_path_placeholder
=
$CLOUD_STORE_BASE_PATH
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Prev
1
2
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets