Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
DARIAH-DE
DARIAH-DE CRUD Services
Commits
3787ef85
Commit
3787ef85
authored
Nov 24, 2021
by
Stefan Funk
Browse files
Merge branch 'release/11.3.0-TG-RELEASE'
parents
a84270d1
0829c9f8
Changes
25
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
.gitlab-ci.yml
View file @
3787ef85
# This template uses jdk8 for verifying and deploying images
image
:
maven:3.8.3-jdk-8
variables
:
# This will suppress any download for dependencies and plugins or upload messages which would clutter the console log.
# `showDateTime` will show the passed time in milliseconds. You need to specify `--batch-mode` to make this work.
...
...
@@ -15,6 +12,25 @@ variables:
# File for storing the POM project.version
VARIABLES_FILE
:
./variables.txt
###################
### TEMPLATES ###
###################
.webapp
:
&webapp
image
:
alpine:3.14
stage
:
deploy_deb
script
:
-
source $VARIABLES_FILE
-
'
apk
add
--no-cache
bash'
-
'
apk
add
--no-cache
curl'
-
export PLOC="$(ls ./${PPATH}/*.deb)"
-
DEB_NAME=$PNAME-$PVERSION.deb
-
'
if
[[
$PVERSION
=~
.*${PKEY}$
]];
then'
-
echo "---A ${PKEY} BUILD IS BEING PERFORMED---"
-
'
curl
-u
${APTLY_USER}:${APTLY_PASSWORD}
-X
POST
--header
"Content-Type:multipart/form-data"
-F
file=@${PLOC}
${APTLY_URL}/files/${DEB_NAME}'
-
'
curl
-u
${APTLY_USER}:${APTLY_PASSWORD}
-X
POST
${APTLY_URL}/repos/${APTLY_TARGET}/file/${DEB_NAME}'
-
'
curl
-u
${APTLY_USER}:${APTLY_PASSWORD}
-X
PUT
-H
"Content-Type:
application/json"
--data
"{}"
${APTLY_URL}/publish/:./indy'
-
fi
stages
:
-
build_version
-
deploy_java
...
...
@@ -29,6 +45,7 @@ cache:
# Get the project version from main POM file and store it to artifact.
get_version
:
image
:
maven:3.8.3-jdk-8
only
:
-
develop
-
main
...
...
@@ -44,6 +61,7 @@ get_version:
# Build and deploy all the JARs to GWDG Nexus, and build all the DEBs and store DEBs to artifacts.
build_and_deploy
:
image
:
maven:3.8.3-jdk-8
only
:
-
develop
-
main
...
...
@@ -61,155 +79,82 @@ build_and_deploy:
# Deploy DEB files to APTLY repository.
# All four DEB files are deployed with SNAPSHOT version (branch: develop)!
# Only the {tg/dh}crud-webapps are deployed for branch main, depending on the version (suffix -TG or -DH)!
# FIXME --> Use a common lib for uploading the deb files to Aptly!
deploy_tgcrud-webapp_dev
:
only
:
-
develop
image
:
alpine:3.14
stage
:
deploy_deb
variables
:
PNAME
:
'
tgcrud-webapp'
PPATH
:
'
${PNAME}/target'
script
:
-
source $VARIABLES_FILE
-
'
apk
add
--no-cache
bash'
-
'
apk
add
--no-cache
curl'
-
export PLOC="$(ls ./${PPATH}/*.deb)"
-
DEB_NAME=$PNAME-$PVERSION.deb
-
'
if
[[
$PVERSION
=~
.*SNAPSHOT$
]];
then
echo
"---A
SNAPSHOT
BUILD
IS
BEING
PERFORMED---";
fi'
-
'
if
[[
$PVERSION
=~
.*SNAPSHOT$
]];
then
curl
-u
${APTLY_USER}:${APTLY_PASSWORD}
-X
POST
--header
"Content-Type:multipart/form-data"
-F
file=@${PLOC}
${APTLY_URL}/files/${DEB_NAME};
fi'
-
'
if
[[
$PVERSION
=~
.*SNAPSHOT$
]];
then
curl
-u
${APTLY_USER}:${APTLY_PASSWORD}
-X
POST
${APTLY_URL}/repos/indy-snapshots/file/${DEB_NAME};
fi'
-
'
if
[[
$PVERSION
=~
.*SNAPSHOT$
]];
then
curl
-u
${APTLY_USER}:${APTLY_PASSWORD}
-X
PUT
-H
"Content-Type:
application/json"
--data
"{}"
${APTLY_URL}/publish/:./indy;
fi'
PKEY
:
'
SNAPSHOT'
APTLY_TARGET
:
'
indy-snapshots'
<<
:
*webapp
deploy_tgcrud-webapp-public_dev
:
only
:
-
develop
image
:
alpine:3.14
stage
:
deploy_deb
variables
:
PNAME
:
'
tgcrud-webapp-public'
PPATH
:
'
${PNAME}/target'
script
:
-
source $VARIABLES_FILE
-
'
apk
add
--no-cache
bash'
-
'
apk
add
--no-cache
curl'
-
export PLOC="$(ls ./${PPATH}/*.deb)"
-
DEB_NAME=$PNAME-$PVERSION.deb
-
'
if
[[
$PVERSION
=~
.*SNAPSHOT$
]];
then
echo
"---A
SNAPSHOT
BUILD
IS
BEING
PERFORMED---";
fi'
-
'
if
[[
$PVERSION
=~
.*SNAPSHOT$
]];
then
curl
-u
${APTLY_USER}:${APTLY_PASSWORD}
-X
POST
--header
"Content-Type:multipart/form-data"
-F
file=@${PLOC}
${APTLY_URL}/files/${DEB_NAME};
fi'
-
'
if
[[
$PVERSION
=~
.*SNAPSHOT$
]];
then
curl
-u
${APTLY_USER}:${APTLY_PASSWORD}
-X
POST
${APTLY_URL}/repos/indy-snapshots/file/${DEB_NAME};
fi'
-
'
if
[[
$PVERSION
=~
.*SNAPSHOT$
]];
then
curl
-u
${APTLY_USER}:${APTLY_PASSWORD}
-X
PUT
-H
"Content-Type:
application/json"
--data
"{}"
${APTLY_URL}/publish/:./indy;
fi'
PKEY
:
'
SNAPSHOT'
APTLY_TARGET
:
'
indy-snapshots'
<<
:
*webapp
deploy_dhcrud-webapp_dev
:
only
:
-
develop
image
:
alpine:3.14
stage
:
deploy_deb
variables
:
PNAME
:
'
dhcrud-webapp'
PPATH
:
'
${PNAME}/target'
script
:
-
source $VARIABLES_FILE
-
'
apk
add
--no-cache
bash'
-
'
apk
add
--no-cache
curl'
-
export PLOC="$(ls ./${PPATH}/*.deb)"
-
DEB_NAME=$PNAME-$PVERSION.deb
-
'
if
[[
$PVERSION
=~
.*SNAPSHOT$
]];
then
echo
"---A
SNAPSHOT
BUILD
IS
BEING
PERFORMED---";
fi'
-
'
if
[[
$PVERSION
=~
.*SNAPSHOT$
]];
then
curl
-u
${APTLY_USER}:${APTLY_PASSWORD}
-X
POST
--header
"Content-Type:multipart/form-data"
-F
file=@${PLOC}
${APTLY_URL}/files/${DEB_NAME};
fi'
-
'
if
[[
$PVERSION
=~
.*SNAPSHOT$
]];
then
curl
-u
${APTLY_USER}:${APTLY_PASSWORD}
-X
POST
${APTLY_URL}/repos/indy-snapshots/file/${DEB_NAME};
fi'
-
'
if
[[
$PVERSION
=~
.*SNAPSHOT$
]];
then
curl
-u
${APTLY_USER}:${APTLY_PASSWORD}
-X
PUT
-H
"Content-Type:
application/json"
--data
"{}"
${APTLY_URL}/publish/:./indy;
fi'
PKEY
:
'
SNAPSHOT'
APTLY_TARGET
:
'
indy-snapshots'
<<
:
*webapp
deploy_dhcrud-webapp-public_dev
:
only
:
-
develop
image
:
alpine:3.14
stage
:
deploy_deb
variables
:
PNAME
:
'
dhcrud-webapp-public'
PPATH
:
'
${PNAME}/target'
script
:
-
source $VARIABLES_FILE
-
'
apk
add
--no-cache
bash'
-
'
apk
add
--no-cache
curl'
-
export PLOC="$(ls ./${PPATH}/*.deb)"
-
DEB_NAME=$PNAME-$PVERSION.deb
-
'
if
[[
$PVERSION
=~
.*SNAPSHOT$
]];
then
echo
"---A
SNAPSHOT
BUILD
IS
BEING
PERFORMED---";
fi'
-
'
if
[[
$PVERSION
=~
.*SNAPSHOT$
]];
then
curl
-u
${APTLY_USER}:${APTLY_PASSWORD}
-X
POST
--header
"Content-Type:multipart/form-data"
-F
file=@${PLOC}
${APTLY_URL}/files/${DEB_NAME};
fi'
-
'
if
[[
$PVERSION
=~
.*SNAPSHOT$
]];
then
curl
-u
${APTLY_USER}:${APTLY_PASSWORD}
-X
POST
${APTLY_URL}/repos/indy-snapshots/file/${DEB_NAME};
fi'
-
'
if
[[
$PVERSION
=~
.*SNAPSHOT$
]];
then
curl
-u
${APTLY_USER}:${APTLY_PASSWORD}
-X
PUT
-H
"Content-Type:
application/json"
--data
"{}"
${APTLY_URL}/publish/:./indy;
fi'
PKEY
:
'
SNAPSHOT'
APTLY_TARGET
:
'
indy-snapshots'
<<
:
*webapp
deploy_tgcrud-webapp_prd
:
only
:
-
main
image
:
alpine:3.14
stage
:
deploy_deb
variables
:
PNAME
:
'
tgcrud-webapp'
PPATH
:
'
${PNAME}/target'
script
:
-
source $VARIABLES_FILE
-
'
apk
add
--no-cache
bash'
-
'
apk
add
--no-cache
curl'
-
export PLOC="$(ls ./${PPATH}/*.deb)"
-
DEB_NAME=$PNAME-$PVERSION.deb
-
'
if
[[
$PVERSION
=~
.*TG-RELEASE$
]];
then
echo
"---A
TGREP
RELEASE
BUILD
IS
BEING
PERFORMED---";
fi'
-
'
if
[[
$PVERSION
=~
.*TG-RELEASE$
]];
then
curl
-u
${APTLY_USER}:${APTLY_PASSWORD}
-X
POST
--header
"Content-Type:multipart/form-data"
-F
file=@${PLOC}
${APTLY_URL}/files/${DEB_NAME};
fi'
-
'
if
[[
$PVERSION
=~
.*TG-RELEASE$
]];
then
curl
-u
${APTLY_USER}:${APTLY_PASSWORD}
-X
POST
${APTLY_URL}/repos/indy-releases/file/${DEB_NAME};
fi'
-
'
if
[[
$PVERSION
=~
.*TG-RELEASE$
]];
then
curl
-u
${APTLY_USER}:${APTLY_PASSWORD}
-X
PUT
-H
"Content-Type:
application/json"
--data
"{}"
${APTLY_URL}/publish/:./indy;
fi'
PKEY
:
'
TG-RELEASE'
APTLY_TARGET
:
'
indy-releases'
<<
:
*webapp
deploy_tgcrud-webapp-public_prd
:
only
:
-
main
image
:
alpine:3.14
stage
:
deploy_deb
variables
:
PNAME
:
'
tgcrud-webapp-public'
PPATH
:
'
${PNAME}/target'
script
:
-
source $VARIABLES_FILE
-
'
apk
add
--no-cache
bash'
-
'
apk
add
--no-cache
curl'
-
export PLOC="$(ls ./${PPATH}/*.deb)"
-
DEB_NAME=$PNAME-$PVERSION.deb
-
'
if
[[
$PVERSION
=~
.*TG-RELEASE$
]];
then
echo
"---A
TGREP
RELEASE
BUILD
IS
BEING
PERFORMED---";
fi'
-
'
if
[[
$PVERSION
=~
.*TG-RELEASE$
]];
then
curl
-u
${APTLY_USER}:${APTLY_PASSWORD}
-X
POST
--header
"Content-Type:multipart/form-data"
-F
file=@${PLOC}
${APTLY_URL}/files/${DEB_NAME};
fi'
-
'
if
[[
$PVERSION
=~
.*TG-RELEASE$
]];
then
curl
-u
${APTLY_USER}:${APTLY_PASSWORD}
-X
POST
${APTLY_URL}/repos/indy-releases/file/${DEB_NAME};
fi'
-
'
if
[[
$PVERSION
=~
.*TG-RELEASE$
]];
then
curl
-u
${APTLY_USER}:${APTLY_PASSWORD}
-X
PUT
-H
"Content-Type:
application/json"
--data
"{}"
${APTLY_URL}/publish/:./indy;
fi'
PKEY
:
'
TG-RELEASE'
APTLY_TARGET
:
'
indy-releases'
<<
:
*webapp
deploy_dhcrud-webapp_prd
:
only
:
-
main
image
:
alpine:3.14
stage
:
deploy_deb
variables
:
PNAME
:
'
dhcrud-webapp'
PPATH
:
'
${PNAME}/target'
script
:
-
source $VARIABLES_FILE
-
'
apk
add
--no-cache
bash'
-
'
apk
add
--no-cache
curl'
-
export PLOC="$(ls ./${PPATH}/*.deb)"
-
DEB_NAME=$PNAME-$PVERSION.deb
-
'
if
[[
$PVERSION
=~
.*DH-RELEASE$
]];
then
echo
"---A
DHREP
RELEASE
BUILD
IS
BEING
PERFORMED---";
fi'
-
'
if
[[
$PVERSION
=~
.*DH-RELEASE$
]];
then
curl
-u
${APTLY_USER}:${APTLY_PASSWORD}
-X
POST
--header
"Content-Type:multipart/form-data"
-F
file=@${PLOC}
${APTLY_URL}/files/${DEB_NAME};
fi'
-
'
if
[[
$PVERSION
=~
.*DH-RELEASE$
]];
then
curl
-u
${APTLY_USER}:${APTLY_PASSWORD}
-X
POST
${APTLY_URL}/repos/indy-releases/file/${DEB_NAME};
fi'
-
'
if
[[
$PVERSION
=~
.*DH-RELEASE$
]];
then
curl
-u
${APTLY_USER}:${APTLY_PASSWORD}
-X
PUT
-H
"Content-Type:
application/json"
--data
"{}"
${APTLY_URL}/publish/:./indy;
fi'
PKEY
:
'
DH-RELEASE'
APTLY_TARGET
:
'
indy-releases'
<<
:
*webapp
deploy_dhcrud-webapp-public_prd
:
only
:
-
main
image
:
alpine:3.14
stage
:
deploy_deb
variables
:
PNAME
:
'
dhcrud-webapp-public'
PPATH
:
'
${PNAME}/target'
script
:
-
source $VARIABLES_FILE
-
'
apk
add
--no-cache
bash'
-
'
apk
add
--no-cache
curl'
-
export PLOC="$(ls ./${PPATH}/*.deb)"
-
DEB_NAME=$PNAME-$PVERSION.deb
-
'
if
[[
$PVERSION
=~
.*DH-RELEASE$
]];
then
echo
"---A
DHREP
RELEASE
BUILD
IS
BEING
PERFORMED---";
fi'
-
'
if
[[
$PVERSION
=~
.*DH-RELEASE$
]];
then
curl
-u
${APTLY_USER}:${APTLY_PASSWORD}
-X
POST
--header
"Content-Type:multipart/form-data"
-F
file=@${PLOC}
${APTLY_URL}/files/${DEB_NAME};
fi'
-
'
if
[[
$PVERSION
=~
.*DH-RELEASE$
]];
then
curl
-u
${APTLY_USER}:${APTLY_PASSWORD}
-X
POST
${APTLY_URL}/repos/indy-releases/file/${DEB_NAME};
fi'
-
'
if
[[
$PVERSION
=~
.*DH-RELEASE$
]];
then
curl
-u
${APTLY_USER}:${APTLY_PASSWORD}
-X
PUT
-H
"Content-Type:
application/json"
--data
"{}"
${APTLY_URL}/publish/:./indy;
fi'
PKEY
:
'
DH-RELEASE'
APTLY_TARGET
:
'
indy-releases'
<<
:
*webapp
CHANGELOG.md
View file @
3787ef85
11.2.0-TG-RELEASE
=================
*
Use Gitlab CI now for build and deployment of JARs and DEBs
11.
1.0-SNAPSHOT
===============
...
...
crud-base/pom.xml
View file @
3787ef85
...
...
@@ -5,7 +5,7 @@
<parent>
<groupId>
info.textgrid.middleware
</groupId>
<artifactId>
crud
</artifactId>
<version>
11.
2
.0-TG-RELEASE
</version>
<version>
11.
3
.0-TG-RELEASE
</version>
</parent>
<artifactId>
crud-base
</artifactId>
<name>
DARIAHDE :: CrudService :: Base
</name>
...
...
crud-base/src/main/java/info/textgrid/namespaces/middleware/tgcrud/services/tgcrudservice/TGCrudServiceIdentifierNoidHazelcastLockingImpl.java
deleted
100644 → 0
View file @
a84270d1
/*******************************************************************************
* This software is copyright (c) 2018 by
*
* - TextGrid Consortium (http://www.textgrid.de)
* - DAASI International GmbH (http://www.daasi.de)
*
* This is free software. You can redistribute it and/or modify it under the
* terms described in the GNU Lesser General Public License v3 of which you
* should have received a copy. Otherwise you can download it from
*
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* @copyright TextGrid Consortium (http://www.textgrid.de)
* @copyright DAASI International GmbH (http://www.daasi.de)
* @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public
* License v3
* @author Stefan E. Funk (stefan.e.funk@daasi.de)
******************************************************************************/
package
info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice
;
import
java.net.URI
;
import
java.util.concurrent.ConcurrentMap
;
import
com.hazelcast.config.Config
;
import
com.hazelcast.core.Hazelcast
;
import
com.hazelcast.core.HazelcastInstance
;
/*******************************************************************************
* TODOLOG
*
*******************************************************************************
* CHANGELOG
*
* 2015-05-12 Funk Copied from TGCrudServiceIdentifierNoidImpl.
*
******************************************************************************/
/*******************************************************************************
* <p>
* This URI implementation creates NOID URIs from a NOID service. Uses Hazelcast
* maps (www.hazelcast.org) for internal and external locking.
* </p>
*
* @author Stefan E. Funk, DAASI International GmbH
* @version 2018-01-12
* @since 2015-05-12
******************************************************************************/
public
class
TGCrudServiceIdentifierNoidHazelcastLockingImpl
extends
TGCrudServiceIdentifierNoidImpl
{
// **
// FINAL STATICS
// **
private
static
final
String
HAZELCAST_IMAP_NAME
=
"tgcrud-internal-locking"
;
private
static
final
String
HAZELCAST_EMAP_NAME
=
"tgcrud-external-locking"
;
// **
// CLASS VARIABLES
// **
private
static
ConcurrentMap
<
URI
,
Boolean
>
iHazelcastMap
;
private
static
ConcurrentMap
<
URI
,
String
>
eHazelcastMap
;
/**
* Constructor: Get the Hazelcast map.
*/
public
TGCrudServiceIdentifierNoidHazelcastLockingImpl
()
{
Config
config
=
new
Config
();
HazelcastInstance
h
=
Hazelcast
.
newHazelcastInstance
(
config
);
iHazelcastMap
=
h
.
getMap
(
HAZELCAST_IMAP_NAME
);
eHazelcastMap
=
h
.
getMap
(
HAZELCAST_EMAP_NAME
);
}
// **
// IMPLEMENTED METHODS
// **
/**
* <p>
* Locks URIs via Hazelcast map, depending on the user ID and automagic
* unlocking time. If an URI is not yet locked, any user is able to lock
* this URI. Only a user, who has locked the object in the first place, can
* re-lock, OR any user if the unlocking time has passed. To keep an object
* locked, the user has to re-lock before the unlocking time has elapsed.
* </p>
*
* @see info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.
* CrudServiceIdentifier#lock(java.net.URI, java.lang.String)
*/
@Override
public
boolean
lock
(
final
URI
theUri
,
final
String
theUser
)
throws
IoFault
{
String
meth
=
UNIT_NAME
+
".lock()"
;
TGCrudServiceUtilities
.
serviceLog
(
CrudService
.
DEBUG
,
meth
,
"eHazelcast map contains URI: "
+
theUri
+
" > "
+
(
eHazelcastMap
.
containsKey
(
theUri
)
?
eHazelcastMap
.
get
(
theUri
)
:
"NO"
));
// If the key is not contained (means the URI is not yet locked), just
// do lock putting in the URI!
if
(!
eHazelcastMap
.
containsKey
(
theUri
))
{
eHazelcastMap
.
put
(
theUri
,
userTimestampValue
(
theUser
));
}
// If key is contained, check locking time and user.
else
{
// Compute locking duration (in millis), parse locking value first.
Long
lockingDuration
=
System
.
currentTimeMillis
()
-
parseLockingValue
(
theUri
);
// Some locking logging :-D
String
lockingDurationString
=
TGCrudServiceUtilities
.
getDuration
(
lockingDuration
);
long
stillLocked
=
this
.
conf
.
getIDaUTOMAGICuNLOCKINGtIME
()
-
lockingDuration
;
String
stillLockedString
=
TGCrudServiceUtilities
.
getDuration
(
stillLocked
);
// Do log.
String
message
=
"Locked since "
+
lockingDurationString
+
" by "
+
theUser
;
if
(
stillLocked
>
0
)
{
message
+=
", automagically unlocked in "
+
stillLockedString
;
}
else
{
message
+=
", automagically unlocking NOW!"
;
}
message
+=
" ["
+
lockingDuration
+
">"
+
this
.
conf
.
getIDaUTOMAGICuNLOCKINGtIME
()
+
"]"
;
TGCrudServiceUtilities
.
serviceLog
(
CrudService
.
DEBUG
,
meth
,
message
);
// Check if user is the one who locked this URI in the first place
// or URI has been locked longer than permitted without re-locking.
// If so, re-lock!
if
(
eHazelcastMap
.
get
(
theUri
).
startsWith
(
theUser
)
||
lockingDuration
>
this
.
conf
.
getIDaUTOMAGICuNLOCKINGtIME
())
{
eHazelcastMap
.
put
(
theUri
,
userTimestampValue
(
theUser
));
}
// Otherwise no locking is allowed!
else
{
return
false
;
}
}
TGCrudServiceUtilities
.
serviceLog
(
CrudService
.
INFO
,
meth
,
"Locking complete: "
+
theUri
);
return
true
;
}
/**
* <p>
* Returns the user ID of the user who locked this URI, if locked, or an
* empty string if URI is not locked (and if the automagic unlocking time
* has not already exceeded) .
* </p>
*
* @see info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.
* CrudServiceIdentifier#isLockedBy(java.net.URI)
*/
@Override
public
String
isLockedBy
(
final
URI
theUri
)
throws
IoFault
{
String
meth
=
UNIT_NAME
+
".isLockedBy()"
;
String
result
=
""
;
TGCrudServiceUtilities
.
serviceLog
(
CrudService
.
DEBUG
,
meth
,
"eHazelcast map contains URI: "
+
theUri
+
" > "
+
(
eHazelcastMap
.
containsKey
(
theUri
)
?
eHazelcastMap
.
get
(
theUri
)
:
"NO"
));
// If key is contained, check locking time and user.
if
(
eHazelcastMap
.
containsKey
(
theUri
))
{
// Compute locking duration (in millis), parse locking value first.
Long
lockingDuration
=
System
.
currentTimeMillis
()
-
parseLockingValue
(
theUri
);
// Some locking logging :-D
String
lockingDurationString
=
TGCrudServiceUtilities
.
getDuration
(
lockingDuration
);
long
stillLocked
=
this
.
conf
.
getIDaUTOMAGICuNLOCKINGtIME
()
-
lockingDuration
;
String
stillLockedString
=
TGCrudServiceUtilities
.
getDuration
(
stillLocked
);
// Do log.
String
message
=
"Locked since "
+
lockingDurationString
;
if
(
stillLocked
>
0
)
{
message
+=
", automagically unlocked in "
+
stillLockedString
;
}
else
{
message
+=
", no external lock is existing anymore"
;
}
// Get the user ID who has a lock on this URI AND check if the URI
// has NOT BEEN locked longer than permitted without re-locking. If
// so, the URI is still locked!
String
value
=
eHazelcastMap
.
get
(
theUri
);
if
(
lockingDuration
<
this
.
conf
.
getIDaUTOMAGICuNLOCKINGtIME
())
{
result
=
value
.
substring
(
0
,
value
.
lastIndexOf
(
USER_TIMESTAMP_SEPARATON_CHAR
))
.
trim
();
TGCrudServiceUtilities
.
serviceLog
(
CrudService
.
DEBUG
,
meth
,
"Locked by user with ID: "
+
result
);
message
+=
" ["
+
lockingDuration
+
"<"
+
this
.
conf
.
getIDaUTOMAGICuNLOCKINGtIME
()
+
"]"
;
}
else
{
message
+=
" ["
+
lockingDuration
+
">"
+
this
.
conf
.
getIDaUTOMAGICuNLOCKINGtIME
()
+
"]"
;
}
TGCrudServiceUtilities
.
serviceLog
(
CrudService
.
DEBUG
,
meth
,
message
);
}
return
result
;
}
/**
* <p>
* Just lock internally, if not yet locked. No further functions are
* included.
* </p>
*
* @see info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.
* CrudServiceIdentifier#lock(java.net.URI)
*/
@Override
public
boolean
lockInternal
(
final
URI
theUri
)
throws
IoFault
{
String
meth
=
UNIT_NAME
+
".lockInternal()"
;
TGCrudServiceUtilities
.
serviceLog
(
CrudService
.
DEBUG
,
meth
,
"iHazelcast map contains key: "
+
theUri
+
" > "
+
(
iHazelcastMap
.
containsKey
(
theUri
)
?
iHazelcastMap
.
get
(
theUri
)
:
"NO"
));
// If the key is contained (means the URI is locked), return false.
if
(
iHazelcastMap
.
containsKey
(
theUri
))
{
return
false
;
}
// Otherwise the key is not contained (means the URI is not yet locked),
// just do lock!
iHazelcastMap
.
put
(
theUri
,
true
);
TGCrudServiceUtilities
.
serviceLog
(
CrudService
.
INFO
,
meth
,
"Locking complete: "
+
theUri
);
return
true
;
}
/**
* <p>
* Unlocks an URI. Unlocking is permitted for the user who has locked the
* object, and for any user, if the automagic unlocking time has elapsed.
* </p>
*
* @see info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.
* CrudServiceIdentifier#unlock(java.net.URI, java.lang.String)
*/
@Override
public
boolean
unlock
(
final
URI
theUri
,
final
String
theUser
)
throws
IoFault
{
String
meth
=
UNIT_NAME
+
".unlock()"
;
TGCrudServiceUtilities
.
serviceLog
(
CrudService
.
DEBUG
,
meth
,
"eHazelcast map contains key: "
+
theUri
+
" > "
+
(
eHazelcastMap
.
containsKey
(
theUri
)
?
eHazelcastMap
.
get
(
theUri
)
:
"NO"
));
// If the key is not contained (means the URI is not yet locked),
// nothing is to unlock.
if
(!
eHazelcastMap
.
containsKey
(
theUri
))
{
return
true
;
}
// If key is contained, check locking time and user.
else
{
// Compute locking duration (in millis), parse locking value first.
Long
lockingDuration
=
System
.
currentTimeMillis
()
-
parseLockingValue
(
theUri
);
// Some locking logging :-D
String
lockingDurationString
=
TGCrudServiceUtilities
.
getDuration
(
lockingDuration
);
long
stillLocked
=
this
.
conf
.
getIDaUTOMAGICuNLOCKINGtIME
()
-
lockingDuration
;
String
stillLockedString
=
TGCrudServiceUtilities
.
getDuration
(
stillLocked
);
// Do log.
String
message
=
"Locked since "
+
lockingDurationString
+
" by "
+
theUser
;
if
(
stillLocked
>
0
)
{
message
+=
", automagically unlocked in "
+
stillLockedString
+
" ["
+
lockingDuration
+
"<"
+
this
.
conf
.
getIDaUTOMAGICuNLOCKINGtIME
()
+
"]"
;
}
else
{
message
+=
", automagically unlocking NOW! ["
+
lockingDuration
+
">"
+
this
.
conf
.
getIDaUTOMAGICuNLOCKINGtIME
()
+
"]"
;
}