Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openbis
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sispub
openbis
Commits
77650871
Commit
77650871
authored
9 years ago
by
felmer
Browse files
Options
Downloads
Patches
Plain Diff
SSDM-2601: some tiny refactoring of FullSampleIdentifier.
SVN: 35015
parent
b02e2f04
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/sample/FullSampleIdentifier.java
+37
-32
37 additions, 32 deletions
...c/server/api/v3/executor/sample/FullSampleIdentifier.java
with
37 additions
and
32 deletions
openbis/source/java/ch/ethz/sis/openbis/generic/server/api/v3/executor/sample/FullSampleIdentifier.java
+
37
−
32
View file @
77650871
...
@@ -37,55 +37,27 @@ class FullSampleIdentifier
...
@@ -37,55 +37,27 @@ class FullSampleIdentifier
FullSampleIdentifier
(
String
sampleIdentifier
)
FullSampleIdentifier
(
String
sampleIdentifier
)
{
{
//Parts Validation
String
[]
parts
=
extractParts
(
sampleIdentifier
);
if
(
StringUtils
.
isBlank
(
sampleIdentifier
))
{
throw
new
IllegalArgumentException
(
"Unspecified sample identifier."
);
}
if
(
sampleIdentifier
.
startsWith
(
"/"
)
==
false
)
{
throw
new
IllegalArgumentException
(
"Sample identifier has to start with a '/': "
+
sampleIdentifier
);
}
String
[]
parts
=
sampleIdentifier
.
split
(
"/"
);
if
(
parts
.
length
==
0
)
{
throw
new
IllegalArgumentException
(
"Sample identifier don't contain any codes: "
+
sampleIdentifier
);
}
else
if
(
parts
.
length
>
4
)
{
throw
new
IllegalArgumentException
(
"Sample identifier can not contain more than three '/': "
+
sampleIdentifier
);
}
//Parts Parsing
String
spaceCode
=
null
;
String
spaceCode
=
null
;
String
projectCode
=
null
;
String
projectCode
=
null
;
String
containerCode
=
null
;
String
containerCode
=
null
;
String
plainSampleCode
=
null
;
String
plainSampleCode
=
null
;
String
code
=
null
;
String
code
=
null
;
if
(
parts
.
length
==
2
)
if
(
parts
.
length
==
2
)
{
{
code
=
parts
[
1
];
code
=
parts
[
1
];
}
if
(
parts
.
length
==
3
)
}
else
if
(
parts
.
length
==
3
)
{
{
spaceCode
=
parts
[
1
];
spaceCode
=
parts
[
1
];
code
=
parts
[
2
];
code
=
parts
[
2
];
}
else
if
(
parts
.
length
==
4
)
}
else
{
{
spaceCode
=
parts
[
1
];
spaceCode
=
parts
[
1
];
projectCode
=
parts
[
2
];
projectCode
=
parts
[
2
];
code
=
parts
[
3
];
code
=
parts
[
3
];
}
}
//Container:Contained validation
String
[]
splittedCode
=
splitCode
(
code
,
sampleIdentifier
);
String
[]
splittedCode
=
code
.
split
(
":"
);
if
(
splittedCode
.
length
>
2
)
{
throw
new
IllegalArgumentException
(
"Sample code can not contain more than one ':': "
+
sampleIdentifier
);
}
//Container:Contained parsing
if
(
splittedCode
.
length
==
2
)
if
(
splittedCode
.
length
==
2
)
{
{
containerCode
=
splittedCode
[
0
];
containerCode
=
splittedCode
[
0
];
...
@@ -105,6 +77,39 @@ class FullSampleIdentifier
...
@@ -105,6 +77,39 @@ class FullSampleIdentifier
}
}
private
String
[]
splitCode
(
String
code
,
String
sampleIdentifier
)
{
String
[]
splittedCode
=
code
.
split
(
":"
);
if
(
splittedCode
.
length
>
2
)
{
throw
new
IllegalArgumentException
(
"Sample code can not contain more than one ':': "
+
sampleIdentifier
);
}
return
splittedCode
;
}
private
String
[]
extractParts
(
String
sampleIdentifier
)
{
if
(
StringUtils
.
isBlank
(
sampleIdentifier
))
{
throw
new
IllegalArgumentException
(
"Unspecified sample identifier."
);
}
if
(
sampleIdentifier
.
startsWith
(
"/"
)
==
false
)
{
throw
new
IllegalArgumentException
(
"Sample identifier has to start with a '/': "
+
sampleIdentifier
);
}
String
[]
parts
=
sampleIdentifier
.
split
(
"/"
);
if
(
parts
.
length
==
0
)
{
throw
new
IllegalArgumentException
(
"Sample identifier don't contain any codes: "
+
sampleIdentifier
);
}
else
if
(
parts
.
length
>
4
)
{
throw
new
IllegalArgumentException
(
"Sample identifier can not contain more than three '/': "
+
sampleIdentifier
);
}
return
parts
;
}
private
void
verifyCodePattern
(
String
code
)
{
private
void
verifyCodePattern
(
String
code
)
{
if
(
code
!=
null
&&
code
.
matches
(
CODE_PATTERN
)
==
false
)
{
if
(
code
!=
null
&&
code
.
matches
(
CODE_PATTERN
)
==
false
)
{
throw
new
IllegalArgumentException
(
"Code field containing other characters than letters, numbers, '_', '-' and '.': "
+
code
);
throw
new
IllegalArgumentException
(
"Code field containing other characters than letters, numbers, '_', '-' and '.': "
+
code
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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