repo stringlengths 7 58 | path stringlengths 12 218 | func_name stringlengths 3 140 | original_string stringlengths 73 34.1k | language stringclasses 1
value | code stringlengths 73 34.1k | code_tokens list | docstring stringlengths 3 16k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 105 339 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/core/util/ResourceUtil.java | ResourceUtil.getPrimaryType | public static String getPrimaryType(Resource resource) {
String result = null;
if (resource != null) {
if (resource instanceof JcrResource) {
// use the resource itself if it implements the JcrResource interface (maybe a version of a resource)
result = ((JcrResource) resource).getPrimaryType();
} else {
Node node = resource.adaptTo(Node.class);
if (node != null) {
try {
NodeType type = node.getPrimaryNodeType();
if (type != null) {
result = type.getName();
}
} catch (RepositoryException ignore) {
}
}
if (result == null) {
ValueMap values = resource.adaptTo(ValueMap.class);
if (values != null) {
result = values.get(JcrConstants.JCR_PRIMARYTYPE, (String) null);
}
}
}
}
return result;
} | java | public static String getPrimaryType(Resource resource) {
String result = null;
if (resource != null) {
if (resource instanceof JcrResource) {
// use the resource itself if it implements the JcrResource interface (maybe a version of a resource)
result = ((JcrResource) resource).getPrimaryType();
} else {
Node node = resource.adaptTo(Node.class);
if (node != null) {
try {
NodeType type = node.getPrimaryNodeType();
if (type != null) {
result = type.getName();
}
} catch (RepositoryException ignore) {
}
}
if (result == null) {
ValueMap values = resource.adaptTo(ValueMap.class);
if (values != null) {
result = values.get(JcrConstants.JCR_PRIMARYTYPE, (String) null);
}
}
}
}
return result;
} | [
"public",
"static",
"String",
"getPrimaryType",
"(",
"Resource",
"resource",
")",
"{",
"String",
"result",
"=",
"null",
";",
"if",
"(",
"resource",
"!=",
"null",
")",
"{",
"if",
"(",
"resource",
"instanceof",
"JcrResource",
")",
"{",
"// use the resource itsel... | retrieves the primary type of the resources node | [
"retrieves",
"the",
"primary",
"type",
"of",
"the",
"resources",
"node"
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/core/util/ResourceUtil.java#L185-L211 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/core/util/ResourceUtil.java | ResourceUtil.getOrCreateChild | public static Resource getOrCreateChild(Resource resource, String relPath, String primaryTypes)
throws RepositoryException {
Resource child = null;
if (resource != null) {
ResourceResolver resolver = resource.getResourceResolver();
String path = resource.getPath();
while (relPath.startsWith("/")) {
relPath = relPath.substring(1);
}
if (StringUtils.isNotBlank(relPath)) {
path += "/" + relPath;
}
child = getOrCreateResource(resolver, path, primaryTypes);
}
return child;
} | java | public static Resource getOrCreateChild(Resource resource, String relPath, String primaryTypes)
throws RepositoryException {
Resource child = null;
if (resource != null) {
ResourceResolver resolver = resource.getResourceResolver();
String path = resource.getPath();
while (relPath.startsWith("/")) {
relPath = relPath.substring(1);
}
if (StringUtils.isNotBlank(relPath)) {
path += "/" + relPath;
}
child = getOrCreateResource(resolver, path, primaryTypes);
}
return child;
} | [
"public",
"static",
"Resource",
"getOrCreateChild",
"(",
"Resource",
"resource",
",",
"String",
"relPath",
",",
"String",
"primaryTypes",
")",
"throws",
"RepositoryException",
"{",
"Resource",
"child",
"=",
"null",
";",
"if",
"(",
"resource",
"!=",
"null",
")",
... | Retrieves the resources child resource, creates this child if not existing.
@param resource the resource to extend
@param relPath the path to the requested child resource
@param primaryTypes the 'path' of primary types for the new nodes (optional, can be 'null')
@return the requested child | [
"Retrieves",
"the",
"resources",
"child",
"resource",
"creates",
"this",
"child",
"if",
"not",
"existing",
"."
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/core/util/ResourceUtil.java#L374-L389 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/core/util/ResourceUtil.java | ResourceUtil.isFile | public static boolean isFile(Resource resource) {
Node node = resource.adaptTo(Node.class);
if (node != null) {
try {
NodeType type = node.getPrimaryNodeType();
if (type != null) {
String typeName = type.getName();
switch (typeName) {
case TYPE_FILE:
return true;
case TYPE_RESOURCE:
case TYPE_UNSTRUCTURED:
try {
Property mimeType = node.getProperty(PROP_MIME_TYPE);
if (mimeType != null && StringUtils.isNotBlank(mimeType.getString())) {
node.getProperty(ResourceUtil.PROP_DATA);
// PathNotFountException if not present
return true;
}
} catch (PathNotFoundException pnfex) {
// ok, was a check only
}
break;
}
}
} catch (RepositoryException e) {
LOG.error(e.getMessage(), e);
}
}
return false;
} | java | public static boolean isFile(Resource resource) {
Node node = resource.adaptTo(Node.class);
if (node != null) {
try {
NodeType type = node.getPrimaryNodeType();
if (type != null) {
String typeName = type.getName();
switch (typeName) {
case TYPE_FILE:
return true;
case TYPE_RESOURCE:
case TYPE_UNSTRUCTURED:
try {
Property mimeType = node.getProperty(PROP_MIME_TYPE);
if (mimeType != null && StringUtils.isNotBlank(mimeType.getString())) {
node.getProperty(ResourceUtil.PROP_DATA);
// PathNotFountException if not present
return true;
}
} catch (PathNotFoundException pnfex) {
// ok, was a check only
}
break;
}
}
} catch (RepositoryException e) {
LOG.error(e.getMessage(), e);
}
}
return false;
} | [
"public",
"static",
"boolean",
"isFile",
"(",
"Resource",
"resource",
")",
"{",
"Node",
"node",
"=",
"resource",
".",
"adaptTo",
"(",
"Node",
".",
"class",
")",
";",
"if",
"(",
"node",
"!=",
"null",
")",
"{",
"try",
"{",
"NodeType",
"type",
"=",
"nod... | Returns 'true' is this resource represents a 'file'. | [
"Returns",
"true",
"is",
"this",
"resource",
"represents",
"a",
"file",
"."
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/core/util/ResourceUtil.java#L452-L482 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/core/AbstractServletBean.java | AbstractServletBean.initialize | @Override
public void initialize(BeanContext context) {
Resource resource = ConsoleUtil.getConsoleResource(context);
initialize(context, ResourceHandle.use(resource));
} | java | @Override
public void initialize(BeanContext context) {
Resource resource = ConsoleUtil.getConsoleResource(context);
initialize(context, ResourceHandle.use(resource));
} | [
"@",
"Override",
"public",
"void",
"initialize",
"(",
"BeanContext",
"context",
")",
"{",
"Resource",
"resource",
"=",
"ConsoleUtil",
".",
"getConsoleResource",
"(",
"context",
")",
";",
"initialize",
"(",
"context",
",",
"ResourceHandle",
".",
"use",
"(",
"re... | extract the resource referenced to display in the browsers view as the components resource | [
"extract",
"the",
"resource",
"referenced",
"to",
"display",
"in",
"the",
"browsers",
"view",
"as",
"the",
"components",
"resource"
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/core/AbstractServletBean.java#L31-L35 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/cpnl/TextTag.java | TextTag.renderTagEnd | @Override
protected void renderTagEnd() {
try {
if (StringUtils.isNotEmpty(this.output)) {
this.output = toString(this.escape
? escape(this.output)
: this.output);
JspWriter writer = this.pageContext.getOut();
boolean renderTag = renderTag()
&& (StringUtils.isNotBlank(this.tagName) || StringUtils.isNotBlank(getClasses()));
if (renderTag) {
super.renderTagStart();
}
writer.write(this.output);
if (renderTag) {
super.renderTagEnd();
}
}
} catch (IOException ioex) {
LOG.error(ioex.getMessage(), ioex);
}
} | java | @Override
protected void renderTagEnd() {
try {
if (StringUtils.isNotEmpty(this.output)) {
this.output = toString(this.escape
? escape(this.output)
: this.output);
JspWriter writer = this.pageContext.getOut();
boolean renderTag = renderTag()
&& (StringUtils.isNotBlank(this.tagName) || StringUtils.isNotBlank(getClasses()));
if (renderTag) {
super.renderTagStart();
}
writer.write(this.output);
if (renderTag) {
super.renderTagEnd();
}
}
} catch (IOException ioex) {
LOG.error(ioex.getMessage(), ioex);
}
} | [
"@",
"Override",
"protected",
"void",
"renderTagEnd",
"(",
")",
"{",
"try",
"{",
"if",
"(",
"StringUtils",
".",
"isNotEmpty",
"(",
"this",
".",
"output",
")",
")",
"{",
"this",
".",
"output",
"=",
"toString",
"(",
"this",
".",
"escape",
"?",
"escape",
... | is rendering the text and a tag around if 'tagName' is set or CSS classes are specified | [
"is",
"rendering",
"the",
"text",
"and",
"a",
"tag",
"around",
"if",
"tagName",
"is",
"set",
"or",
"CSS",
"classes",
"are",
"specified"
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/cpnl/TextTag.java#L154-L175 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/cpnl/TextTag.java | TextTag.escape | protected Object escape(Object value) {
EscapeFunction function = ESCAPE_FUNCTION_MAP.get(this.type);
return function != null ? function.escape(TagUtil.getRequest(this.pageContext), value) : CpnlElFunctions.text(toString(value));
} | java | protected Object escape(Object value) {
EscapeFunction function = ESCAPE_FUNCTION_MAP.get(this.type);
return function != null ? function.escape(TagUtil.getRequest(this.pageContext), value) : CpnlElFunctions.text(toString(value));
} | [
"protected",
"Object",
"escape",
"(",
"Object",
"value",
")",
"{",
"EscapeFunction",
"function",
"=",
"ESCAPE_FUNCTION_MAP",
".",
"get",
"(",
"this",
".",
"type",
")",
";",
"return",
"function",
"!=",
"null",
"?",
"function",
".",
"escape",
"(",
"TagUtil",
... | the extension hook for the various types of encoding; must work with Object values to ensure
that non String values can be used as is
@param value the value (String) to encode
@return the encoded String or an appropriate Object | [
"the",
"extension",
"hook",
"for",
"the",
"various",
"types",
"of",
"encoding",
";",
"must",
"work",
"with",
"Object",
"values",
"to",
"ensure",
"that",
"non",
"String",
"values",
"can",
"be",
"used",
"as",
"is"
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/cpnl/TextTag.java#L188-L191 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/core/util/JsonUtil.java | JsonUtil.exportJson | public static void exportJson(JsonWriter writer, Resource resource)
throws RepositoryException, IOException {
exportJson(writer, resource, MappingRules.getDefaultMappingRules());
} | java | public static void exportJson(JsonWriter writer, Resource resource)
throws RepositoryException, IOException {
exportJson(writer, resource, MappingRules.getDefaultMappingRules());
} | [
"public",
"static",
"void",
"exportJson",
"(",
"JsonWriter",
"writer",
",",
"Resource",
"resource",
")",
"throws",
"RepositoryException",
",",
"IOException",
"{",
"exportJson",
"(",
"writer",
",",
"resource",
",",
"MappingRules",
".",
"getDefaultMappingRules",
"(",
... | Writes a resources JSON view to a writer using the default application rules for filtering.
@param writer the writer for the JSON transformation
@param resource the resource to transform
@throws RepositoryException
@throws IOException | [
"Writes",
"a",
"resources",
"JSON",
"view",
"to",
"a",
"writer",
"using",
"the",
"default",
"application",
"rules",
"for",
"filtering",
"."
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/core/util/JsonUtil.java#L198-L201 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/core/util/JsonUtil.java | JsonUtil.parseJsonProperty | public static JsonProperty parseJsonProperty(JsonReader reader, String name)
throws RepositoryException, IOException {
JsonToken token = reader.peek();
JsonProperty property = new JsonProperty();
property.name = name;
switch (token) {
case BOOLEAN:
// map boolean values directly if not a string
property.type = PropertyType.nameFromValue(PropertyType.BOOLEAN);
property.value = reader.nextBoolean();
break;
case NUMBER:
// map numver values to LONG directly if not a string
property.type = PropertyType.nameFromValue(PropertyType.LONG);
property.value = reader.nextLong();
break;
case STRING:
// parse the string with an option type hint within
parseJsonString(reader, property);
break;
case NULL:
reader.nextNull();
break;
}
return property;
} | java | public static JsonProperty parseJsonProperty(JsonReader reader, String name)
throws RepositoryException, IOException {
JsonToken token = reader.peek();
JsonProperty property = new JsonProperty();
property.name = name;
switch (token) {
case BOOLEAN:
// map boolean values directly if not a string
property.type = PropertyType.nameFromValue(PropertyType.BOOLEAN);
property.value = reader.nextBoolean();
break;
case NUMBER:
// map numver values to LONG directly if not a string
property.type = PropertyType.nameFromValue(PropertyType.LONG);
property.value = reader.nextLong();
break;
case STRING:
// parse the string with an option type hint within
parseJsonString(reader, property);
break;
case NULL:
reader.nextNull();
break;
}
return property;
} | [
"public",
"static",
"JsonProperty",
"parseJsonProperty",
"(",
"JsonReader",
"reader",
",",
"String",
"name",
")",
"throws",
"RepositoryException",
",",
"IOException",
"{",
"JsonToken",
"token",
"=",
"reader",
".",
"peek",
"(",
")",
";",
"JsonProperty",
"property",... | Parses a single property of the first element of an array and returns the result as a JSON POJO object.
@param reader the reader with the JSON stream
@param name the already parsed name of the property
@return a new JsonProperty object with the name, type, and value set
@throws RepositoryException
@throws IOException | [
"Parses",
"a",
"single",
"property",
"of",
"the",
"first",
"element",
"of",
"an",
"array",
"and",
"returns",
"the",
"result",
"as",
"a",
"JSON",
"POJO",
"object",
"."
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/core/util/JsonUtil.java#L565-L590 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/core/util/JsonUtil.java | JsonUtil.getValueString | public static String getValueString(Object value, int type, MappingRules mapping) {
String string = value.toString();
if (type != PropertyType.STRING &&
mapping.propertyFormat.embedType &&
mapping.propertyFormat.scope == MappingRules.PropertyFormat.Scope.value) {
string = "{" + PropertyType.nameFromValue(type) + "}" + string;
}
return string;
} | java | public static String getValueString(Object value, int type, MappingRules mapping) {
String string = value.toString();
if (type != PropertyType.STRING &&
mapping.propertyFormat.embedType &&
mapping.propertyFormat.scope == MappingRules.PropertyFormat.Scope.value) {
string = "{" + PropertyType.nameFromValue(type) + "}" + string;
}
return string;
} | [
"public",
"static",
"String",
"getValueString",
"(",
"Object",
"value",
",",
"int",
"type",
",",
"MappingRules",
"mapping",
")",
"{",
"String",
"string",
"=",
"value",
".",
"toString",
"(",
")",
";",
"if",
"(",
"type",
"!=",
"PropertyType",
".",
"STRING",
... | Embeds the property type in the string value if the formats scope is 'value'.
@param value
@param type
@param mapping
@return | [
"Embeds",
"the",
"property",
"type",
"in",
"the",
"string",
"value",
"if",
"the",
"formats",
"scope",
"is",
"value",
"."
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/core/util/JsonUtil.java#L948-L956 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/core/util/JsonUtil.java | JsonUtil.makeJcrValue | public static Value makeJcrValue(Node node, int type, Object object,
MappingRules mapping)
throws PropertyValueFormatException, RepositoryException {
Session session = node.getSession();
ValueFactory factory = session.getValueFactory();
Value value = null;
if (object != null) {
switch (type) {
case PropertyType.BINARY:
if (mapping.propertyFormat.binary != MappingRules.PropertyFormat.Binary.skip) {
InputStream input = null;
if (object instanceof InputStream) {
input = (InputStream) object;
} else if (object instanceof String) {
if (mapping.propertyFormat.binary == MappingRules.PropertyFormat.Binary.base64) {
byte[] decoded = Base64.decodeBase64((String) object);
input = new ByteArrayInputStream(decoded);
}
}
if (input != null) {
Binary binary = factory.createBinary(input);
value = factory.createValue(binary);
}
}
break;
case PropertyType.BOOLEAN:
value = factory.createValue(object instanceof Boolean
? (Boolean) object : Boolean.parseBoolean(object.toString()));
break;
case PropertyType.DATE:
Date date = object instanceof Date ? (Date) object : null;
if (date == null) {
String string = object.toString();
date = mapping.dateParser.parse(string);
}
if (date != null) {
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(date);
value = factory.createValue(cal);
} else {
throw new PropertyValueFormatException("invalid date/time value: " + object);
}
break;
case PropertyType.DECIMAL:
value = factory.createValue(object instanceof BigDecimal
? (BigDecimal) object : new BigDecimal(object.toString()));
break;
case PropertyType.DOUBLE:
value = factory.createValue(object instanceof Double
? (Double) object : Double.parseDouble(object.toString()));
break;
case PropertyType.LONG:
value = factory.createValue(object instanceof Long
? (Long) object : Long.parseLong(object.toString()));
break;
case PropertyType.REFERENCE:
case PropertyType.WEAKREFERENCE:
final Node refNode = session.getNodeByIdentifier(object.toString());
final String identifier = refNode.getIdentifier();
value = factory.createValue(identifier, type);
break;
case PropertyType.NAME:
case PropertyType.PATH:
case PropertyType.STRING:
case PropertyType.URI:
value = factory.createValue(object.toString(), type);
break;
case PropertyType.UNDEFINED:
break;
}
}
return value;
} | java | public static Value makeJcrValue(Node node, int type, Object object,
MappingRules mapping)
throws PropertyValueFormatException, RepositoryException {
Session session = node.getSession();
ValueFactory factory = session.getValueFactory();
Value value = null;
if (object != null) {
switch (type) {
case PropertyType.BINARY:
if (mapping.propertyFormat.binary != MappingRules.PropertyFormat.Binary.skip) {
InputStream input = null;
if (object instanceof InputStream) {
input = (InputStream) object;
} else if (object instanceof String) {
if (mapping.propertyFormat.binary == MappingRules.PropertyFormat.Binary.base64) {
byte[] decoded = Base64.decodeBase64((String) object);
input = new ByteArrayInputStream(decoded);
}
}
if (input != null) {
Binary binary = factory.createBinary(input);
value = factory.createValue(binary);
}
}
break;
case PropertyType.BOOLEAN:
value = factory.createValue(object instanceof Boolean
? (Boolean) object : Boolean.parseBoolean(object.toString()));
break;
case PropertyType.DATE:
Date date = object instanceof Date ? (Date) object : null;
if (date == null) {
String string = object.toString();
date = mapping.dateParser.parse(string);
}
if (date != null) {
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(date);
value = factory.createValue(cal);
} else {
throw new PropertyValueFormatException("invalid date/time value: " + object);
}
break;
case PropertyType.DECIMAL:
value = factory.createValue(object instanceof BigDecimal
? (BigDecimal) object : new BigDecimal(object.toString()));
break;
case PropertyType.DOUBLE:
value = factory.createValue(object instanceof Double
? (Double) object : Double.parseDouble(object.toString()));
break;
case PropertyType.LONG:
value = factory.createValue(object instanceof Long
? (Long) object : Long.parseLong(object.toString()));
break;
case PropertyType.REFERENCE:
case PropertyType.WEAKREFERENCE:
final Node refNode = session.getNodeByIdentifier(object.toString());
final String identifier = refNode.getIdentifier();
value = factory.createValue(identifier, type);
break;
case PropertyType.NAME:
case PropertyType.PATH:
case PropertyType.STRING:
case PropertyType.URI:
value = factory.createValue(object.toString(), type);
break;
case PropertyType.UNDEFINED:
break;
}
}
return value;
} | [
"public",
"static",
"Value",
"makeJcrValue",
"(",
"Node",
"node",
",",
"int",
"type",
",",
"Object",
"object",
",",
"MappingRules",
"mapping",
")",
"throws",
"PropertyValueFormatException",
",",
"RepositoryException",
"{",
"Session",
"session",
"=",
"node",
".",
... | Create a JCR value from string value for the designated JCR type.
@param node the node of the property
@param type the JCR type according to the types declared in PropertyType
@param object the value in the right type or a string representation of the value,
for binary values a input stream can be used as parameter or a string
with the base64 encoded data for the binary property
@return | [
"Create",
"a",
"JCR",
"value",
"from",
"string",
"value",
"for",
"the",
"designated",
"JCR",
"type",
"."
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/core/util/JsonUtil.java#L1128-L1201 | train |
ist-dresden/composum | sling/core/setup/util/src/main/java/com/composum/sling/core/setup/util/SetupUtil.java | SetupUtil.setupGroupsAndUsers | public static void setupGroupsAndUsers(InstallContext ctx,
Map<String, List<String>> groups,
Map<String, List<String>> systemUsers,
Map<String, List<String>> users) throws PackageException {
UserManagementService userManagementService = getService(UserManagementService.class);
try {
JackrabbitSession session = (JackrabbitSession) ctx.getSession();
UserManager userManager = session.getUserManager();
if (groups != null) {
for (Map.Entry<String, List<String>> entry : groups.entrySet()) {
Group group = userManagementService.getOrCreateGroup(session, userManager, entry.getKey());
if (group != null) {
for (String memberName : entry.getValue()) {
userManagementService.assignToGroup(session, userManager, memberName, group);
}
}
}
session.save();
}
if (systemUsers != null) {
for (Map.Entry<String, List<String>> entry : systemUsers.entrySet()) {
Authorizable user = userManagementService.getOrCreateUser(session, userManager, entry.getKey(), true);
if (user != null) {
for (String groupName : entry.getValue()) {
userManagementService.assignToGroup(session, userManager, user, groupName);
}
}
}
session.save();
}
if (users != null) {
for (Map.Entry<String, List<String>> entry : users.entrySet()) {
Authorizable user = userManagementService.getOrCreateUser(session, userManager, entry.getKey(), false);
if (user != null) {
for (String groupName : entry.getValue()) {
userManagementService.assignToGroup(session, userManager, user, groupName);
}
}
}
session.save();
}
} catch (RepositoryException | RuntimeException rex) {
LOG.error(rex.getMessage(), rex);
throw new PackageException(rex);
}
} | java | public static void setupGroupsAndUsers(InstallContext ctx,
Map<String, List<String>> groups,
Map<String, List<String>> systemUsers,
Map<String, List<String>> users) throws PackageException {
UserManagementService userManagementService = getService(UserManagementService.class);
try {
JackrabbitSession session = (JackrabbitSession) ctx.getSession();
UserManager userManager = session.getUserManager();
if (groups != null) {
for (Map.Entry<String, List<String>> entry : groups.entrySet()) {
Group group = userManagementService.getOrCreateGroup(session, userManager, entry.getKey());
if (group != null) {
for (String memberName : entry.getValue()) {
userManagementService.assignToGroup(session, userManager, memberName, group);
}
}
}
session.save();
}
if (systemUsers != null) {
for (Map.Entry<String, List<String>> entry : systemUsers.entrySet()) {
Authorizable user = userManagementService.getOrCreateUser(session, userManager, entry.getKey(), true);
if (user != null) {
for (String groupName : entry.getValue()) {
userManagementService.assignToGroup(session, userManager, user, groupName);
}
}
}
session.save();
}
if (users != null) {
for (Map.Entry<String, List<String>> entry : users.entrySet()) {
Authorizable user = userManagementService.getOrCreateUser(session, userManager, entry.getKey(), false);
if (user != null) {
for (String groupName : entry.getValue()) {
userManagementService.assignToGroup(session, userManager, user, groupName);
}
}
}
session.save();
}
} catch (RepositoryException | RuntimeException rex) {
LOG.error(rex.getMessage(), rex);
throw new PackageException(rex);
}
} | [
"public",
"static",
"void",
"setupGroupsAndUsers",
"(",
"InstallContext",
"ctx",
",",
"Map",
"<",
"String",
",",
"List",
"<",
"String",
">",
">",
"groups",
",",
"Map",
"<",
"String",
",",
"List",
"<",
"String",
">",
">",
"systemUsers",
",",
"Map",
"<",
... | Creates or updates a set of groups, users and system users
@param ctx the installation context
@param groups map of group names (including path, e.g. composum/plaform/composum-platform-users) to list of
users (have to exist already)
@param systemUsers map of system user names (including path, e.g. system/composum/platform/composum-platform-service)
to list of group names (without path). The groups have to exist already, or be created with parameter groups
@param users map of user names (including path) to list of group names (without path). The groups
have to exist already, or be created with parameter groups
@throws PackageException | [
"Creates",
"or",
"updates",
"a",
"set",
"of",
"groups",
"users",
"and",
"system",
"users"
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/setup/util/src/main/java/com/composum/sling/core/setup/util/SetupUtil.java#L37-L82 | train |
ist-dresden/composum | sling/core/setup/util/src/main/java/com/composum/sling/core/setup/util/SetupUtil.java | SetupUtil.getService | @SuppressWarnings("unchecked")
public static <T> T getService(Class<T> type) {
Bundle serviceBundle = FrameworkUtil.getBundle(type);
BundleContext serviceBundleContext = serviceBundle.getBundleContext();
ServiceReference serviceReference = serviceBundleContext.getServiceReference(type.getName());
return (T) serviceBundleContext.getService(serviceReference);
} | java | @SuppressWarnings("unchecked")
public static <T> T getService(Class<T> type) {
Bundle serviceBundle = FrameworkUtil.getBundle(type);
BundleContext serviceBundleContext = serviceBundle.getBundleContext();
ServiceReference serviceReference = serviceBundleContext.getServiceReference(type.getName());
return (T) serviceBundleContext.getService(serviceReference);
} | [
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"public",
"static",
"<",
"T",
">",
"T",
"getService",
"(",
"Class",
"<",
"T",
">",
"type",
")",
"{",
"Bundle",
"serviceBundle",
"=",
"FrameworkUtil",
".",
"getBundle",
"(",
"type",
")",
";",
"BundleContex... | retrieve a service during setup | [
"retrieve",
"a",
"service",
"during",
"setup"
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/setup/util/src/main/java/com/composum/sling/core/setup/util/SetupUtil.java#L132-L138 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/clientlibs/processor/ProcessingVisitor.java | ProcessingVisitor.alreadyProcessed | @Override
protected void alreadyProcessed(ClientlibRef ref, VisitorMode mode, ClientlibResourceFolder folder) {
if (mode == EMBEDDED) {
LOG.warn("Trying to embed already embedded / dependency {} again at {}", ref, folder);
}
} | java | @Override
protected void alreadyProcessed(ClientlibRef ref, VisitorMode mode, ClientlibResourceFolder folder) {
if (mode == EMBEDDED) {
LOG.warn("Trying to embed already embedded / dependency {} again at {}", ref, folder);
}
} | [
"@",
"Override",
"protected",
"void",
"alreadyProcessed",
"(",
"ClientlibRef",
"ref",
",",
"VisitorMode",
"mode",
",",
"ClientlibResourceFolder",
"folder",
")",
"{",
"if",
"(",
"mode",
"==",
"EMBEDDED",
")",
"{",
"LOG",
".",
"warn",
"(",
"\"Trying to embed alrea... | Warns about everything that should be embedded, but is already processed, and not in this | [
"Warns",
"about",
"everything",
"that",
"should",
"be",
"embedded",
"but",
"is",
"already",
"processed",
"and",
"not",
"in",
"this"
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/clientlibs/processor/ProcessingVisitor.java#L87-L92 | train |
ist-dresden/composum | sling/core/usermgnt/src/main/java/com/composum/sling/core/usermanagement/core/UserMgmtServiceImpl.java | UserMgmtServiceImpl.getOrCreateUser | public Authorizable getOrCreateUser(JackrabbitSession session, UserManager userManager,
String path, boolean systemUser)
throws RepositoryException {
String[] pathAndName = pathAndName(path);
Authorizable user = userManager.getAuthorizable(pathAndName[1]);
LOG.debug("user.check: " + pathAndName[1] + " - " + user);
if (user == null) {
LOG.info("user.create: " + pathAndName[1]);
Principal principal = new NamePrincipal(pathAndName[1]);
if (systemUser) {
try {
// using reflection to create systems users for compatibility to older API versions
Method createSystemUser = userManager.getClass().getMethod("createSystemUser", String.class, String.class);
user = (User) createSystemUser.invoke(userManager, pathAndName[1], pathAndName[0]);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
LOG.error(ex.toString());
}
} else {
user = userManager.createUser(pathAndName[1], pathAndName[1],
principal, pathAndName[0]);
}
}
return user;
} | java | public Authorizable getOrCreateUser(JackrabbitSession session, UserManager userManager,
String path, boolean systemUser)
throws RepositoryException {
String[] pathAndName = pathAndName(path);
Authorizable user = userManager.getAuthorizable(pathAndName[1]);
LOG.debug("user.check: " + pathAndName[1] + " - " + user);
if (user == null) {
LOG.info("user.create: " + pathAndName[1]);
Principal principal = new NamePrincipal(pathAndName[1]);
if (systemUser) {
try {
// using reflection to create systems users for compatibility to older API versions
Method createSystemUser = userManager.getClass().getMethod("createSystemUser", String.class, String.class);
user = (User) createSystemUser.invoke(userManager, pathAndName[1], pathAndName[0]);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
LOG.error(ex.toString());
}
} else {
user = userManager.createUser(pathAndName[1], pathAndName[1],
principal, pathAndName[0]);
}
}
return user;
} | [
"public",
"Authorizable",
"getOrCreateUser",
"(",
"JackrabbitSession",
"session",
",",
"UserManager",
"userManager",
",",
"String",
"path",
",",
"boolean",
"systemUser",
")",
"throws",
"RepositoryException",
"{",
"String",
"[",
"]",
"pathAndName",
"=",
"pathAndName",
... | Retrieves a user by its name; if the user doesn't exist the user will be created.
@param path the name of the user with an optional prepended intermediate path for user creation | [
"Retrieves",
"a",
"user",
"by",
"its",
"name",
";",
"if",
"the",
"user",
"doesn",
"t",
"exist",
"the",
"user",
"will",
"be",
"created",
"."
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/usermgnt/src/main/java/com/composum/sling/core/usermanagement/core/UserMgmtServiceImpl.java#L29-L52 | train |
ist-dresden/composum | sling/core/usermgnt/src/main/java/com/composum/sling/core/usermanagement/core/UserMgmtServiceImpl.java | UserMgmtServiceImpl.getOrCreateGroup | public Group getOrCreateGroup(JackrabbitSession session, UserManager userManager,
String path)
throws RepositoryException {
String[] pathAndName = pathAndName(path);
Group group = (Group) userManager.getAuthorizable(pathAndName[1]);
LOG.debug("group.check: " + pathAndName[1] + " - " + group);
if (group == null) {
LOG.info("group.create: " + pathAndName[1]);
group = userManager.createGroup(new NamePrincipal(pathAndName[1]), pathAndName[0]);
}
return group;
} | java | public Group getOrCreateGroup(JackrabbitSession session, UserManager userManager,
String path)
throws RepositoryException {
String[] pathAndName = pathAndName(path);
Group group = (Group) userManager.getAuthorizable(pathAndName[1]);
LOG.debug("group.check: " + pathAndName[1] + " - " + group);
if (group == null) {
LOG.info("group.create: " + pathAndName[1]);
group = userManager.createGroup(new NamePrincipal(pathAndName[1]), pathAndName[0]);
}
return group;
} | [
"public",
"Group",
"getOrCreateGroup",
"(",
"JackrabbitSession",
"session",
",",
"UserManager",
"userManager",
",",
"String",
"path",
")",
"throws",
"RepositoryException",
"{",
"String",
"[",
"]",
"pathAndName",
"=",
"pathAndName",
"(",
"path",
")",
";",
"Group",
... | Retrieves a group by their name; if the group doesn't exist the group will be created.
@param path the name of the group with an optional prepended intermediate path for group creation | [
"Retrieves",
"a",
"group",
"by",
"their",
"name",
";",
"if",
"the",
"group",
"doesn",
"t",
"exist",
"the",
"group",
"will",
"be",
"created",
"."
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/usermgnt/src/main/java/com/composum/sling/core/usermanagement/core/UserMgmtServiceImpl.java#L59-L70 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/clientlibs/handle/ClientlibRef.java | ClientlibRef.isSatisfiedby | public boolean isSatisfiedby(ClientlibLink link) {
if (!type.equals(link.type)) return false;
if (isCategory()) {
if (!link.isCategory() || !category.equals(link.path)) return false;
} else if (isExternalUri()) {
if (!link.isExternalUri() || !externalUri.equals(link.path)) return false;
} else {
if (link.isCategory() || link.isExternalUri() || !pattern.matcher(link.path).matches()) return false;
}
if (!properties.equals(link.properties))
return false;
return true;
} | java | public boolean isSatisfiedby(ClientlibLink link) {
if (!type.equals(link.type)) return false;
if (isCategory()) {
if (!link.isCategory() || !category.equals(link.path)) return false;
} else if (isExternalUri()) {
if (!link.isExternalUri() || !externalUri.equals(link.path)) return false;
} else {
if (link.isCategory() || link.isExternalUri() || !pattern.matcher(link.path).matches()) return false;
}
if (!properties.equals(link.properties))
return false;
return true;
} | [
"public",
"boolean",
"isSatisfiedby",
"(",
"ClientlibLink",
"link",
")",
"{",
"if",
"(",
"!",
"type",
".",
"equals",
"(",
"link",
".",
"type",
")",
")",
"return",
"false",
";",
"if",
"(",
"isCategory",
"(",
")",
")",
"{",
"if",
"(",
"!",
"link",
".... | Checks whether the link matches this, up to version patterns. | [
"Checks",
"whether",
"the",
"link",
"matches",
"this",
"up",
"to",
"version",
"patterns",
"."
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/clientlibs/handle/ClientlibRef.java#L66-L78 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/clientlibs/handle/ClientlibRef.java | ClientlibRef.isSatisfiedby | public boolean isSatisfiedby(Collection<ClientlibLink> links) {
for (ClientlibLink link : links) if (isSatisfiedby(link)) return true;
return false;
} | java | public boolean isSatisfiedby(Collection<ClientlibLink> links) {
for (ClientlibLink link : links) if (isSatisfiedby(link)) return true;
return false;
} | [
"public",
"boolean",
"isSatisfiedby",
"(",
"Collection",
"<",
"ClientlibLink",
">",
"links",
")",
"{",
"for",
"(",
"ClientlibLink",
"link",
":",
"links",
")",
"if",
"(",
"isSatisfiedby",
"(",
"link",
")",
")",
"return",
"true",
";",
"return",
"false",
";",... | Checks whether one of the links matches this, up to version patterns. | [
"Checks",
"whether",
"one",
"of",
"the",
"links",
"matches",
"this",
"up",
"to",
"version",
"patterns",
"."
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/clientlibs/handle/ClientlibRef.java#L81-L84 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/core/util/LinkUtil.java | LinkUtil.getAbsoluteUrl | public static String getAbsoluteUrl(SlingHttpServletRequest request, String url) {
if (!isExternalUrl(url) && url.startsWith("/")) {
String scheme = request.getScheme().toLowerCase();
url = scheme + "://" + getAuthority(request) + url;
}
return url;
} | java | public static String getAbsoluteUrl(SlingHttpServletRequest request, String url) {
if (!isExternalUrl(url) && url.startsWith("/")) {
String scheme = request.getScheme().toLowerCase();
url = scheme + "://" + getAuthority(request) + url;
}
return url;
} | [
"public",
"static",
"String",
"getAbsoluteUrl",
"(",
"SlingHttpServletRequest",
"request",
",",
"String",
"url",
")",
"{",
"if",
"(",
"!",
"isExternalUrl",
"(",
"url",
")",
"&&",
"url",
".",
"startsWith",
"(",
"\"/\"",
")",
")",
"{",
"String",
"scheme",
"=... | Makes a URL already built external; the url should be built by the 'getUrl' method.
@param request the request as the externalization context
@param url the url value (the local URL)
@return | [
"Makes",
"a",
"URL",
"already",
"built",
"external",
";",
"the",
"url",
"should",
"be",
"built",
"by",
"the",
"getUrl",
"method",
"."
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/core/util/LinkUtil.java#L182-L188 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/core/util/LinkUtil.java | LinkUtil.resolveUrl | public static Resource resolveUrl(SlingHttpServletRequest request, String url) {
return request.getResourceResolver().getResource(url);
} | java | public static Resource resolveUrl(SlingHttpServletRequest request, String url) {
return request.getResourceResolver().getResource(url);
} | [
"public",
"static",
"Resource",
"resolveUrl",
"(",
"SlingHttpServletRequest",
"request",
",",
"String",
"url",
")",
"{",
"return",
"request",
".",
"getResourceResolver",
"(",
")",
".",
"getResource",
"(",
"url",
")",
";",
"}"
] | Returns the resource referenced by an URL. | [
"Returns",
"the",
"resource",
"referenced",
"by",
"an",
"URL",
"."
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/core/util/LinkUtil.java#L247-L249 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/core/util/LinkUtil.java | LinkUtil.getFinalTarget | public static String getFinalTarget(Resource resource) throws RedirectLoopException {
ResourceHandle handle = ResourceHandle.use(resource);
String finalTarget = getFinalTarget(handle, new ArrayList<String>());
return finalTarget;
} | java | public static String getFinalTarget(Resource resource) throws RedirectLoopException {
ResourceHandle handle = ResourceHandle.use(resource);
String finalTarget = getFinalTarget(handle, new ArrayList<String>());
return finalTarget;
} | [
"public",
"static",
"String",
"getFinalTarget",
"(",
"Resource",
"resource",
")",
"throws",
"RedirectLoopException",
"{",
"ResourceHandle",
"handle",
"=",
"ResourceHandle",
".",
"use",
"(",
"resource",
")",
";",
"String",
"finalTarget",
"=",
"getFinalTarget",
"(",
... | Retrieves the target for a resource if there are redirects declared.
@return the target path or url (can be external); 'null' if no redirect detected
@throws RedirectLoopException if a 'loop' has been detected during redirect resolving | [
"Retrieves",
"the",
"target",
"for",
"a",
"resource",
"if",
"there",
"are",
"redirects",
"declared",
"."
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/core/util/LinkUtil.java#L257-L261 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/core/util/LinkUtil.java | LinkUtil.getFinalTarget | protected static String getFinalTarget(ResourceHandle resource, List<String> trace)
throws RedirectLoopException {
String finalTarget = null;
if (resource.isValid()) {
String path = resource.getPath();
if (trace.contains(path)) {
// throw an exception if a loop has been detected
throw new RedirectLoopException(trace, path);
}
// search for redirects and resolve them...
String redirect = resource.getProperty(PROP_TARGET);
if (StringUtils.isBlank(redirect)) {
redirect = resource.getProperty(PROP_REDIRECT);
}
if (StringUtils.isBlank(redirect)) {
// try to use the properties of a 'jcr:content' child instead of the target resource itself
ResourceHandle contentResource = resource.getContentResource();
if (resource != contentResource) {
redirect = contentResource.getProperty(PROP_TARGET);
if (StringUtils.isBlank(redirect)) {
redirect = contentResource.getProperty(PROP_REDIRECT);
}
}
}
if (StringUtils.isNotBlank(redirect)) {
trace.add(path);
finalTarget = redirect; // use the redirect target as the link URL
if (!URL_PATTERN.matcher(finalTarget).matches()) {
// look forward if the redirect found points to another resource
ResourceResolver resolver = resource.getResourceResolver();
Resource targetResource = resolver.getResource(finalTarget);
if (targetResource != null) {
String target = getFinalTarget(ResourceHandle.use(targetResource), trace);
if (StringUtils.isNotBlank(target)) {
finalTarget = target;
}
}
}
}
}
return finalTarget;
} | java | protected static String getFinalTarget(ResourceHandle resource, List<String> trace)
throws RedirectLoopException {
String finalTarget = null;
if (resource.isValid()) {
String path = resource.getPath();
if (trace.contains(path)) {
// throw an exception if a loop has been detected
throw new RedirectLoopException(trace, path);
}
// search for redirects and resolve them...
String redirect = resource.getProperty(PROP_TARGET);
if (StringUtils.isBlank(redirect)) {
redirect = resource.getProperty(PROP_REDIRECT);
}
if (StringUtils.isBlank(redirect)) {
// try to use the properties of a 'jcr:content' child instead of the target resource itself
ResourceHandle contentResource = resource.getContentResource();
if (resource != contentResource) {
redirect = contentResource.getProperty(PROP_TARGET);
if (StringUtils.isBlank(redirect)) {
redirect = contentResource.getProperty(PROP_REDIRECT);
}
}
}
if (StringUtils.isNotBlank(redirect)) {
trace.add(path);
finalTarget = redirect; // use the redirect target as the link URL
if (!URL_PATTERN.matcher(finalTarget).matches()) {
// look forward if the redirect found points to another resource
ResourceResolver resolver = resource.getResourceResolver();
Resource targetResource = resolver.getResource(finalTarget);
if (targetResource != null) {
String target = getFinalTarget(ResourceHandle.use(targetResource), trace);
if (StringUtils.isNotBlank(target)) {
finalTarget = target;
}
}
}
}
}
return finalTarget;
} | [
"protected",
"static",
"String",
"getFinalTarget",
"(",
"ResourceHandle",
"resource",
",",
"List",
"<",
"String",
">",
"trace",
")",
"throws",
"RedirectLoopException",
"{",
"String",
"finalTarget",
"=",
"null",
";",
"if",
"(",
"resource",
".",
"isValid",
"(",
... | Determines the 'final URL' of a link to a resource by traversing along the 'redirect' properties.
@param resource the addressed resource
@param trace the list of paths traversed before (to detect loops in redirects)
@return a 'final' path or URL; <code>null</code> if no different target found
@throws RedirectLoopException if a redirect loop has been detected | [
"Determines",
"the",
"final",
"URL",
"of",
"a",
"link",
"to",
"a",
"resource",
"by",
"traversing",
"along",
"the",
"redirect",
"properties",
"."
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/core/util/LinkUtil.java#L271-L312 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/core/servlet/AbstractConsoleServlet.java | AbstractConsoleServlet.checkConsoleAccess | protected boolean checkConsoleAccess(BeanContext context) {
String consolePath = getConsolePath(context);
if (StringUtils.isNotBlank(consolePath)) {
return context.getResolver().getResource(consolePath) != null;
}
return true;
} | java | protected boolean checkConsoleAccess(BeanContext context) {
String consolePath = getConsolePath(context);
if (StringUtils.isNotBlank(consolePath)) {
return context.getResolver().getResource(consolePath) != null;
}
return true;
} | [
"protected",
"boolean",
"checkConsoleAccess",
"(",
"BeanContext",
"context",
")",
"{",
"String",
"consolePath",
"=",
"getConsolePath",
"(",
"context",
")",
";",
"if",
"(",
"StringUtils",
".",
"isNotBlank",
"(",
"consolePath",
")",
")",
"{",
"return",
"context",
... | Check access rights to the servlets path - is checking ACLs of the console path
@param context the current request
@return 'true' if access granted or access check switched off | [
"Check",
"access",
"rights",
"to",
"the",
"servlets",
"path",
"-",
"is",
"checking",
"ACLs",
"of",
"the",
"console",
"path"
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/core/servlet/AbstractConsoleServlet.java#L113-L119 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/clientlibs/handle/Clientlib.java | Clientlib.makeLink | @Override
public ClientlibLink makeLink() {
return new ClientlibLink(getType(), ClientlibLink.Kind.CLIENTLIB, resource.getPath(), null);
} | java | @Override
public ClientlibLink makeLink() {
return new ClientlibLink(getType(), ClientlibLink.Kind.CLIENTLIB, resource.getPath(), null);
} | [
"@",
"Override",
"public",
"ClientlibLink",
"makeLink",
"(",
")",
"{",
"return",
"new",
"ClientlibLink",
"(",
"getType",
"(",
")",
",",
"ClientlibLink",
".",
"Kind",
".",
"CLIENTLIB",
",",
"resource",
".",
"getPath",
"(",
")",
",",
"null",
")",
";",
"}"
... | A link that matches this. | [
"A",
"link",
"that",
"matches",
"this",
"."
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/clientlibs/handle/Clientlib.java#L50-L53 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/cpnl/CpnlElFunctions.java | CpnlElFunctions.child | public static String child(Resource base, String path) {
Resource child = base.getChild(path);
return child != null ? child.getPath() : path;
} | java | public static String child(Resource base, String path) {
Resource child = base.getChild(path);
return child != null ? child.getPath() : path;
} | [
"public",
"static",
"String",
"child",
"(",
"Resource",
"base",
",",
"String",
"path",
")",
"{",
"Resource",
"child",
"=",
"base",
".",
"getChild",
"(",
"path",
")",
";",
"return",
"child",
"!=",
"null",
"?",
"child",
".",
"getPath",
"(",
")",
":",
"... | Returns the repository path of a child of a resource.
@param base the parent resource object
@param path the relative path to the child resource
@return the absolute path of the child if found, otherwise the original path value | [
"Returns",
"the",
"repository",
"path",
"of",
"a",
"child",
"of",
"a",
"resource",
"."
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/cpnl/CpnlElFunctions.java#L164-L167 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/cpnl/CpnlElFunctions.java | CpnlElFunctions.map | public static String map(SlingHttpServletRequest request, String value) {
StringBuilder result = new StringBuilder();
Matcher matcher = HREF_PATTERN.matcher(value);
int len = value.length();
int pos = 0;
while (matcher.find(pos)) {
String unmapped = matcher.group(3);
String mapped = url(request, unmapped);
result.append(value, pos, matcher.start());
result.append(matcher.group(1));
result.append(mapped);
result.append(matcher.group(4));
pos = matcher.end();
}
if (pos >= 0 && pos < len) {
result.append(value, pos, len);
}
return result.toString();
} | java | public static String map(SlingHttpServletRequest request, String value) {
StringBuilder result = new StringBuilder();
Matcher matcher = HREF_PATTERN.matcher(value);
int len = value.length();
int pos = 0;
while (matcher.find(pos)) {
String unmapped = matcher.group(3);
String mapped = url(request, unmapped);
result.append(value, pos, matcher.start());
result.append(matcher.group(1));
result.append(mapped);
result.append(matcher.group(4));
pos = matcher.end();
}
if (pos >= 0 && pos < len) {
result.append(value, pos, len);
}
return result.toString();
} | [
"public",
"static",
"String",
"map",
"(",
"SlingHttpServletRequest",
"request",
",",
"String",
"value",
")",
"{",
"StringBuilder",
"result",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"Matcher",
"matcher",
"=",
"HREF_PATTERN",
".",
"matcher",
"(",
"value",
")... | Replaces all 'href' attribute values found in the text value by the resolver mapped value.
@param request the text (rich text) value
@param value the text (rich text) value
@return the transformed text value | [
"Replaces",
"all",
"href",
"attribute",
"values",
"found",
"in",
"the",
"text",
"value",
"by",
"the",
"resolver",
"mapped",
"value",
"."
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/cpnl/CpnlElFunctions.java#L300-L318 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/cpnl/CpnlElFunctions.java | CpnlElFunctions.path | public static String path(String value) {
return value != null ? LinkUtil.encodePath(value) : null;
} | java | public static String path(String value) {
return value != null ? LinkUtil.encodePath(value) : null;
} | [
"public",
"static",
"String",
"path",
"(",
"String",
"value",
")",
"{",
"return",
"value",
"!=",
"null",
"?",
"LinkUtil",
".",
"encodePath",
"(",
"value",
")",
":",
"null",
";",
"}"
] | Returns the encoded path of a of a repository path.
@param value the path to encode
@return the encoded path | [
"Returns",
"the",
"encoded",
"path",
"of",
"a",
"of",
"a",
"repository",
"path",
"."
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/cpnl/CpnlElFunctions.java#L326-L328 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/cpnl/CpnlElFunctions.java | CpnlElFunctions.getFormatter | public static Format getFormatter(@Nonnull final Locale locale, @Nonnull final String format,
@Nullable final Class<?>... type) {
Format formatter = null;
Pattern TEXT_FORMAT_STRING = Pattern.compile("^\\{([^}]+)}(.+)$");
Matcher matcher = TEXT_FORMAT_STRING.matcher(format);
if (matcher.matches()) {
switch (matcher.group(1)) {
case "Message":
formatter = new MessageFormat(matcher.group(2), locale);
break;
case "Date":
formatter = new SimpleDateFormat(matcher.group(2), locale);
break;
case "String":
formatter = new FormatterFormat(matcher.group(2), locale);
break;
default:
case "Log":
formatter = new LoggerFormat(matcher.group(2));
break;
}
} else {
if (type != null && type.length == 1 && type[0] != null &&
(Calendar.class.isAssignableFrom(type[0]) || Date.class.isAssignableFrom(type[0]))) {
formatter = new SimpleDateFormat(format, locale);
} else {
formatter = new LoggerFormat(format);
}
}
return formatter;
} | java | public static Format getFormatter(@Nonnull final Locale locale, @Nonnull final String format,
@Nullable final Class<?>... type) {
Format formatter = null;
Pattern TEXT_FORMAT_STRING = Pattern.compile("^\\{([^}]+)}(.+)$");
Matcher matcher = TEXT_FORMAT_STRING.matcher(format);
if (matcher.matches()) {
switch (matcher.group(1)) {
case "Message":
formatter = new MessageFormat(matcher.group(2), locale);
break;
case "Date":
formatter = new SimpleDateFormat(matcher.group(2), locale);
break;
case "String":
formatter = new FormatterFormat(matcher.group(2), locale);
break;
default:
case "Log":
formatter = new LoggerFormat(matcher.group(2));
break;
}
} else {
if (type != null && type.length == 1 && type[0] != null &&
(Calendar.class.isAssignableFrom(type[0]) || Date.class.isAssignableFrom(type[0]))) {
formatter = new SimpleDateFormat(format, locale);
} else {
formatter = new LoggerFormat(format);
}
}
return formatter;
} | [
"public",
"static",
"Format",
"getFormatter",
"(",
"@",
"Nonnull",
"final",
"Locale",
"locale",
",",
"@",
"Nonnull",
"final",
"String",
"format",
",",
"@",
"Nullable",
"final",
"Class",
"<",
"?",
">",
"...",
"type",
")",
"{",
"Format",
"formatter",
"=",
... | Creates the formatter for a describing string rule
@param locale the local to use for formatting
@param format the format string rule
@param type the optional value type
@return the Format instance | [
"Creates",
"the",
"formatter",
"for",
"a",
"describing",
"string",
"rule"
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/cpnl/CpnlElFunctions.java#L358-L388 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/core/ResourceHandle.java | ResourceHandle.use | public static ResourceHandle use(Resource resource) {
return resource instanceof ResourceHandle
? ((ResourceHandle) resource) : new ResourceHandle(resource);
} | java | public static ResourceHandle use(Resource resource) {
return resource instanceof ResourceHandle
? ((ResourceHandle) resource) : new ResourceHandle(resource);
} | [
"public",
"static",
"ResourceHandle",
"use",
"(",
"Resource",
"resource",
")",
"{",
"return",
"resource",
"instanceof",
"ResourceHandle",
"?",
"(",
"(",
"ResourceHandle",
")",
"resource",
")",
":",
"new",
"ResourceHandle",
"(",
"resource",
")",
";",
"}"
] | The 'adaptTo' like wrapping helper.
@return the wrapped resource (may be resource itself if it is a ResourceHandle), not null | [
"The",
"adaptTo",
"like",
"wrapping",
"helper",
"."
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/core/ResourceHandle.java#L41-L44 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/core/ResourceHandle.java | ResourceHandle.isValid | public static boolean isValid(Resource resource) {
return resource instanceof ResourceHandle
? ((ResourceHandle) resource).isValid()
: resource != null && resource.getResourceResolver().getResource(resource.getPath()) != null;
} | java | public static boolean isValid(Resource resource) {
return resource instanceof ResourceHandle
? ((ResourceHandle) resource).isValid()
: resource != null && resource.getResourceResolver().getResource(resource.getPath()) != null;
} | [
"public",
"static",
"boolean",
"isValid",
"(",
"Resource",
"resource",
")",
"{",
"return",
"resource",
"instanceof",
"ResourceHandle",
"?",
"(",
"(",
"ResourceHandle",
")",
"resource",
")",
".",
"isValid",
"(",
")",
":",
"resource",
"!=",
"null",
"&&",
"reso... | the universal validation test | [
"the",
"universal",
"validation",
"test"
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/core/ResourceHandle.java#L47-L51 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/core/ResourceHandle.java | ResourceHandle.isValid | public boolean isValid() {
if (valid == null) {
valid = (this.resource != null);
if (valid) {
valid = (getResourceResolver().getResource(getPath()) != null);
}
}
return valid;
} | java | public boolean isValid() {
if (valid == null) {
valid = (this.resource != null);
if (valid) {
valid = (getResourceResolver().getResource(getPath()) != null);
}
}
return valid;
} | [
"public",
"boolean",
"isValid",
"(",
")",
"{",
"if",
"(",
"valid",
"==",
"null",
")",
"{",
"valid",
"=",
"(",
"this",
".",
"resource",
"!=",
"null",
")",
";",
"if",
"(",
"valid",
")",
"{",
"valid",
"=",
"(",
"getResourceResolver",
"(",
")",
".",
... | a resource is valid if not 'null' and resolvable | [
"a",
"resource",
"is",
"valid",
"if",
"not",
"null",
"and",
"resolvable"
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/core/ResourceHandle.java#L100-L108 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/core/ResourceHandle.java | ResourceHandle.getId | public String getId() {
if (id == null) {
if (isValid()) {
id = getProperty(ResourceUtil.PROP_UUID);
}
if (StringUtils.isBlank(id)) {
id = Base64.encodeBase64String(getPath().getBytes(MappingRules.CHARSET));
}
}
return id;
} | java | public String getId() {
if (id == null) {
if (isValid()) {
id = getProperty(ResourceUtil.PROP_UUID);
}
if (StringUtils.isBlank(id)) {
id = Base64.encodeBase64String(getPath().getBytes(MappingRules.CHARSET));
}
}
return id;
} | [
"public",
"String",
"getId",
"(",
")",
"{",
"if",
"(",
"id",
"==",
"null",
")",
"{",
"if",
"(",
"isValid",
"(",
")",
")",
"{",
"id",
"=",
"getProperty",
"(",
"ResourceUtil",
".",
"PROP_UUID",
")",
";",
"}",
"if",
"(",
"StringUtils",
".",
"isBlank",... | Lazy getter for the ID of the resources. The ID is the UUID of the resources node if available otherwise the
Base64 encoded path.
@return a hopefully useful ID (not <code>null</code>) | [
"Lazy",
"getter",
"for",
"the",
"ID",
"of",
"the",
"resources",
".",
"The",
"ID",
"is",
"the",
"UUID",
"of",
"the",
"resources",
"node",
"if",
"available",
"otherwise",
"the",
"Base64",
"encoded",
"path",
"."
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/core/ResourceHandle.java#L322-L332 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/core/ResourceHandle.java | ResourceHandle.getChildrenByType | public List<ResourceHandle> getChildrenByType(final String type) {
final ArrayList<ResourceHandle> children = new ArrayList<>();
if (this.isValid()) {
for (final Resource child : this.resource.getChildren()) {
ResourceHandle handle = ResourceHandle.use(child);
if (handle.isOfType(type)) {
children.add(handle);
}
}
}
return children;
} | java | public List<ResourceHandle> getChildrenByType(final String type) {
final ArrayList<ResourceHandle> children = new ArrayList<>();
if (this.isValid()) {
for (final Resource child : this.resource.getChildren()) {
ResourceHandle handle = ResourceHandle.use(child);
if (handle.isOfType(type)) {
children.add(handle);
}
}
}
return children;
} | [
"public",
"List",
"<",
"ResourceHandle",
">",
"getChildrenByType",
"(",
"final",
"String",
"type",
")",
"{",
"final",
"ArrayList",
"<",
"ResourceHandle",
">",
"children",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"if",
"(",
"this",
".",
"isValid",
"(",... | retrieves all children of a type | [
"retrieves",
"all",
"children",
"of",
"a",
"type"
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/core/ResourceHandle.java#L470-L481 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/core/util/NodeUtil.java | NodeUtil.getId | public String getId(Node node) {
String id = null;
try {
id = node.getIdentifier();
} catch (RepositoryException e) {
id = node.toString(); // use Java 'ID'
}
return id;
} | java | public String getId(Node node) {
String id = null;
try {
id = node.getIdentifier();
} catch (RepositoryException e) {
id = node.toString(); // use Java 'ID'
}
return id;
} | [
"public",
"String",
"getId",
"(",
"Node",
"node",
")",
"{",
"String",
"id",
"=",
"null",
";",
"try",
"{",
"id",
"=",
"node",
".",
"getIdentifier",
"(",
")",
";",
"}",
"catch",
"(",
"RepositoryException",
"e",
")",
"{",
"id",
"=",
"node",
".",
"toSt... | Retrieves the nodes id.
@return a hopefully useful ID (not <code>null</code>) | [
"Retrieves",
"the",
"nodes",
"id",
"."
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/core/util/NodeUtil.java#L28-L36 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/core/util/NodeUtil.java | NodeUtil.getTitle | public static String getTitle(Node node) {
String title = getNodeTitle(node);
if (StringUtils.isBlank(title)) {
try {
title = node.getName();
} catch (RepositoryException rex) {
LOG.error(rex.getMessage(), rex);
}
}
return title;
} | java | public static String getTitle(Node node) {
String title = getNodeTitle(node);
if (StringUtils.isBlank(title)) {
try {
title = node.getName();
} catch (RepositoryException rex) {
LOG.error(rex.getMessage(), rex);
}
}
return title;
} | [
"public",
"static",
"String",
"getTitle",
"(",
"Node",
"node",
")",
"{",
"String",
"title",
"=",
"getNodeTitle",
"(",
"node",
")",
";",
"if",
"(",
"StringUtils",
".",
"isBlank",
"(",
"title",
")",
")",
"{",
"try",
"{",
"title",
"=",
"node",
".",
"get... | Retrieves the title with a fallback to the nodes name.
@param node
@return the usable title (not blank) | [
"Retrieves",
"the",
"title",
"with",
"a",
"fallback",
"to",
"the",
"nodes",
"name",
"."
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/core/util/NodeUtil.java#L44-L54 | train |
ist-dresden/composum | sling/core/pckginstall/src/main/java/com/composum/sling/core/pckginstall/PackageTransformer.java | PackageTransformer.getManifest | private static Manifest getManifest(final RegisteredResource rsrc) throws IOException {
try (final InputStream ins = rsrc.getInputStream()) {
if (ins != null) {
try (JarInputStream jis = new JarInputStream(ins)) {
return jis.getManifest();
}
} else {
return null;
}
}
} | java | private static Manifest getManifest(final RegisteredResource rsrc) throws IOException {
try (final InputStream ins = rsrc.getInputStream()) {
if (ins != null) {
try (JarInputStream jis = new JarInputStream(ins)) {
return jis.getManifest();
}
} else {
return null;
}
}
} | [
"private",
"static",
"Manifest",
"getManifest",
"(",
"final",
"RegisteredResource",
"rsrc",
")",
"throws",
"IOException",
"{",
"try",
"(",
"final",
"InputStream",
"ins",
"=",
"rsrc",
".",
"getInputStream",
"(",
")",
")",
"{",
"if",
"(",
"ins",
"!=",
"null",
... | Read the manifest from supplied input stream, which is closed before return. | [
"Read",
"the",
"manifest",
"from",
"supplied",
"input",
"stream",
"which",
"is",
"closed",
"before",
"return",
"."
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/pckginstall/src/main/java/com/composum/sling/core/pckginstall/PackageTransformer.java#L194-L204 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/core/util/PropertyUtil.java | PropertyUtil.readValue | public static <T> T readValue(Value value, Class<T> type) throws RepositoryException {
try {
if (null == value) return null;
if (type.isAssignableFrom(value.getClass())) return type.cast(value);
if (Long.class.equals(type)) return type.cast(value.getLong());
if (Integer.class.equals(type)) return type.cast(value.getLong());
if (Short.class.equals(type)) return type.cast((short) value.getLong());
if (Byte.class.equals(type)) return type.cast((byte) value.getLong());
if (Float.class.equals(type)) return type.cast((float) value.getLong());
if (Double.class.equals(type)) return type.cast(value.getDouble());
if (String.class.equals(type)) return type.cast(value.getString());
if (Boolean.class.equals(type)) return type.cast(value.getBoolean());
if (java.net.URI.class.equals(type)) return type.cast(new URI(value.getString()));
if (java.net.URL.class.equals(type)) return type.cast(new URL(value.getString()));
if (Date.class.equals(type)) return type.cast(value.getDate().getTime());
if (Calendar.class.equals(type)) return type.cast(value.getDate());
if (BigDecimal.class.equals(type)) return type.cast(value.getDecimal());
if (Binary.class.equals(type)) return type.cast(value.getBinary());
if (InputStream.class.equals(type)) return type.cast(value.getBinary().getStream());
Class defaultType = DEFAULT_PROPERTY_TYPES.get(value.getType());
if (null != defaultType && type.isAssignableFrom(defaultType))
return type.cast(readValue(value, defaultType));
throw new IllegalArgumentException("Type " + type + " not supported yet.");
} catch (URISyntaxException | MalformedURLException | RuntimeException e) {
throw new ValueFormatException("Can't convert to " + type, e);
}
} | java | public static <T> T readValue(Value value, Class<T> type) throws RepositoryException {
try {
if (null == value) return null;
if (type.isAssignableFrom(value.getClass())) return type.cast(value);
if (Long.class.equals(type)) return type.cast(value.getLong());
if (Integer.class.equals(type)) return type.cast(value.getLong());
if (Short.class.equals(type)) return type.cast((short) value.getLong());
if (Byte.class.equals(type)) return type.cast((byte) value.getLong());
if (Float.class.equals(type)) return type.cast((float) value.getLong());
if (Double.class.equals(type)) return type.cast(value.getDouble());
if (String.class.equals(type)) return type.cast(value.getString());
if (Boolean.class.equals(type)) return type.cast(value.getBoolean());
if (java.net.URI.class.equals(type)) return type.cast(new URI(value.getString()));
if (java.net.URL.class.equals(type)) return type.cast(new URL(value.getString()));
if (Date.class.equals(type)) return type.cast(value.getDate().getTime());
if (Calendar.class.equals(type)) return type.cast(value.getDate());
if (BigDecimal.class.equals(type)) return type.cast(value.getDecimal());
if (Binary.class.equals(type)) return type.cast(value.getBinary());
if (InputStream.class.equals(type)) return type.cast(value.getBinary().getStream());
Class defaultType = DEFAULT_PROPERTY_TYPES.get(value.getType());
if (null != defaultType && type.isAssignableFrom(defaultType))
return type.cast(readValue(value, defaultType));
throw new IllegalArgumentException("Type " + type + " not supported yet.");
} catch (URISyntaxException | MalformedURLException | RuntimeException e) {
throw new ValueFormatException("Can't convert to " + type, e);
}
} | [
"public",
"static",
"<",
"T",
">",
"T",
"readValue",
"(",
"Value",
"value",
",",
"Class",
"<",
"T",
">",
"type",
")",
"throws",
"RepositoryException",
"{",
"try",
"{",
"if",
"(",
"null",
"==",
"value",
")",
"return",
"null",
";",
"if",
"(",
"type",
... | Reads the value of a property as the given type. | [
"Reads",
"the",
"value",
"of",
"a",
"property",
"as",
"the",
"given",
"type",
"."
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/core/util/PropertyUtil.java#L294-L324 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/core/util/MimeTypeUtil.java | MimeTypeUtil.getParentMimeType | private static MimeType getParentMimeType(Resource resource) {
MimeType result = null;
if (resource != null && (resource = resource.getParent()) != null) {
ResourceHandle handle = ResourceHandle.use(resource);
result = getMimeType(handle.getProperty(ResourceUtil.PROP_MIME_TYPE, ""));
if (result == null) {
String filename = getResourceName(resource);
result = getMimeType(filename);
}
}
return result;
} | java | private static MimeType getParentMimeType(Resource resource) {
MimeType result = null;
if (resource != null && (resource = resource.getParent()) != null) {
ResourceHandle handle = ResourceHandle.use(resource);
result = getMimeType(handle.getProperty(ResourceUtil.PROP_MIME_TYPE, ""));
if (result == null) {
String filename = getResourceName(resource);
result = getMimeType(filename);
}
}
return result;
} | [
"private",
"static",
"MimeType",
"getParentMimeType",
"(",
"Resource",
"resource",
")",
"{",
"MimeType",
"result",
"=",
"null",
";",
"if",
"(",
"resource",
"!=",
"null",
"&&",
"(",
"resource",
"=",
"resource",
".",
"getParent",
"(",
")",
")",
"!=",
"null",... | a helper if the resource is a content node an should use its parent as a fallback | [
"a",
"helper",
"if",
"the",
"resource",
"is",
"a",
"content",
"node",
"an",
"should",
"use",
"its",
"parent",
"as",
"a",
"fallback"
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/core/util/MimeTypeUtil.java#L107-L118 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/core/util/MimeTypeUtil.java | MimeTypeUtil.getContentMimeType | private static MimeType getContentMimeType(Resource resource) {
MimeType result = null;
if (resource != null && (resource = resource.getChild(ResourceUtil.CONTENT_NODE)) != null) {
ResourceHandle handle = ResourceHandle.use(resource);
result = getMimeType(handle.getProperty(ResourceUtil.PROP_MIME_TYPE, ""));
}
return result;
} | java | private static MimeType getContentMimeType(Resource resource) {
MimeType result = null;
if (resource != null && (resource = resource.getChild(ResourceUtil.CONTENT_NODE)) != null) {
ResourceHandle handle = ResourceHandle.use(resource);
result = getMimeType(handle.getProperty(ResourceUtil.PROP_MIME_TYPE, ""));
}
return result;
} | [
"private",
"static",
"MimeType",
"getContentMimeType",
"(",
"Resource",
"resource",
")",
"{",
"MimeType",
"result",
"=",
"null",
";",
"if",
"(",
"resource",
"!=",
"null",
"&&",
"(",
"resource",
"=",
"resource",
".",
"getChild",
"(",
"ResourceUtil",
".",
"CON... | a helper if the resource has a content node an should use this content as a fallback | [
"a",
"helper",
"if",
"the",
"resource",
"has",
"a",
"content",
"node",
"an",
"should",
"use",
"this",
"content",
"as",
"a",
"fallback"
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/core/util/MimeTypeUtil.java#L123-L130 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/core/util/MimeTypeUtil.java | MimeTypeUtil.getMimeType | public static MimeType getMimeType(String value) {
if (StringUtils.isNotBlank(value)) {
try {
return getMimeTypes().forName(value);
} catch (MimeTypeException e) {
MediaType mediaType = getMediaType(null, value);
if (mediaType != null) {
try {
return getMimeTypes().forName(mediaType.toString());
} catch (MimeTypeException e1) {
// detection not successful
}
}
}
}
return null;
} | java | public static MimeType getMimeType(String value) {
if (StringUtils.isNotBlank(value)) {
try {
return getMimeTypes().forName(value);
} catch (MimeTypeException e) {
MediaType mediaType = getMediaType(null, value);
if (mediaType != null) {
try {
return getMimeTypes().forName(mediaType.toString());
} catch (MimeTypeException e1) {
// detection not successful
}
}
}
}
return null;
} | [
"public",
"static",
"MimeType",
"getMimeType",
"(",
"String",
"value",
")",
"{",
"if",
"(",
"StringUtils",
".",
"isNotBlank",
"(",
"value",
")",
")",
"{",
"try",
"{",
"return",
"getMimeTypes",
"(",
")",
".",
"forName",
"(",
"value",
")",
";",
"}",
"cat... | Retrieves the MimeType object according to a name value
@param value the name hint; can be a mime type value or a filename | [
"Retrieves",
"the",
"MimeType",
"object",
"according",
"to",
"a",
"name",
"value"
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/core/util/MimeTypeUtil.java#L240-L256 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/core/AbstractSlingBean.java | AbstractSlingBean.initialize | public void initialize(BeanContext context, Resource resource) {
if (LOG.isDebugEnabled()) {
LOG.debug("initialize (" + context + ", " + resource + ")");
}
this.context = context;
this.resource = ResourceHandle.use(resource);
} | java | public void initialize(BeanContext context, Resource resource) {
if (LOG.isDebugEnabled()) {
LOG.debug("initialize (" + context + ", " + resource + ")");
}
this.context = context;
this.resource = ResourceHandle.use(resource);
} | [
"public",
"void",
"initialize",
"(",
"BeanContext",
"context",
",",
"Resource",
"resource",
")",
"{",
"if",
"(",
"LOG",
".",
"isDebugEnabled",
"(",
")",
")",
"{",
"LOG",
".",
"debug",
"(",
"\"initialize (\"",
"+",
"context",
"+",
"\", \"",
"+",
"resource",... | This basic initialization sets up the context and resource attributes only,
all the other attributes are set 'lazy' during their getter calls.
@param context the scripting context (e.g. a JSP PageContext or a Groovy scripting context)
@param resource the resource to use (normally the resource addressed by the request) | [
"This",
"basic",
"initialization",
"sets",
"up",
"the",
"context",
"and",
"resource",
"attributes",
"only",
"all",
"the",
"other",
"attributes",
"are",
"set",
"lazy",
"during",
"their",
"getter",
"calls",
"."
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/core/AbstractSlingBean.java#L104-L110 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/core/AbstractSlingBean.java | AbstractSlingBean.getParent | public ResourceHandle getParent(String resourceType) {
ResourceHandle result = getResource();
while (result.isValid() && !result.isResourceType(resourceType)) {
result = result.getParent();
}
if (!result.isValid()) {
result = getParent(resourceType, getPath()); // implicit fallback to the path
}
return result;
} | java | public ResourceHandle getParent(String resourceType) {
ResourceHandle result = getResource();
while (result.isValid() && !result.isResourceType(resourceType)) {
result = result.getParent();
}
if (!result.isValid()) {
result = getParent(resourceType, getPath()); // implicit fallback to the path
}
return result;
} | [
"public",
"ResourceHandle",
"getParent",
"(",
"String",
"resourceType",
")",
"{",
"ResourceHandle",
"result",
"=",
"getResource",
"(",
")",
";",
"while",
"(",
"result",
".",
"isValid",
"(",
")",
"&&",
"!",
"result",
".",
"isResourceType",
"(",
"resourceType",
... | Determine a typed parent resource. | [
"Determine",
"a",
"typed",
"parent",
"resource",
"."
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/core/AbstractSlingBean.java#L200-L209 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/core/RequestHandle.java | RequestHandle.getExtension | public String getExtension() {
String extension = getSlingRequest().getRequestPathInfo().getExtension();
return StringUtils.isBlank(extension) ? "" : ("." + extension);
} | java | public String getExtension() {
String extension = getSlingRequest().getRequestPathInfo().getExtension();
return StringUtils.isBlank(extension) ? "" : ("." + extension);
} | [
"public",
"String",
"getExtension",
"(",
")",
"{",
"String",
"extension",
"=",
"getSlingRequest",
"(",
")",
".",
"getRequestPathInfo",
"(",
")",
".",
"getExtension",
"(",
")",
";",
"return",
"StringUtils",
".",
"isBlank",
"(",
"extension",
")",
"?",
"\"\"",
... | Returns the request extension with a leading '.' if present. | [
"Returns",
"the",
"request",
"extension",
"with",
"a",
"leading",
".",
"if",
"present",
"."
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/core/RequestHandle.java#L78-L81 | train |
ist-dresden/composum | sling/core/usermgnt/src/main/java/com/composum/sling/core/usermanagement/view/User.java | User.isCurrentUserAdmin | public boolean isCurrentUserAdmin() throws RepositoryException {
boolean isAdmin = false;
final JackrabbitSession session = (JackrabbitSession) getSession();
final UserManager userManager = session.getUserManager();
Authorizable a = userManager.getAuthorizable(getRequest().getUserPrincipal());
if (a instanceof org.apache.jackrabbit.api.security.user.User) {
isAdmin = ((org.apache.jackrabbit.api.security.user.User)a).isAdmin();
}
return isAdmin;
} | java | public boolean isCurrentUserAdmin() throws RepositoryException {
boolean isAdmin = false;
final JackrabbitSession session = (JackrabbitSession) getSession();
final UserManager userManager = session.getUserManager();
Authorizable a = userManager.getAuthorizable(getRequest().getUserPrincipal());
if (a instanceof org.apache.jackrabbit.api.security.user.User) {
isAdmin = ((org.apache.jackrabbit.api.security.user.User)a).isAdmin();
}
return isAdmin;
} | [
"public",
"boolean",
"isCurrentUserAdmin",
"(",
")",
"throws",
"RepositoryException",
"{",
"boolean",
"isAdmin",
"=",
"false",
";",
"final",
"JackrabbitSession",
"session",
"=",
"(",
"JackrabbitSession",
")",
"getSession",
"(",
")",
";",
"final",
"UserManager",
"u... | Returns true if the current request user is the admin user. | [
"Returns",
"true",
"if",
"the",
"current",
"request",
"user",
"is",
"the",
"admin",
"user",
"."
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/usermgnt/src/main/java/com/composum/sling/core/usermanagement/view/User.java#L69-L78 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/clientlibs/processor/ProcessorContext.java | ProcessorContext.submit | public <T> Future<T> submit(Callable<T> callable) {
return executorService.submit(callable);
} | java | public <T> Future<T> submit(Callable<T> callable) {
return executorService.submit(callable);
} | [
"public",
"<",
"T",
">",
"Future",
"<",
"T",
">",
"submit",
"(",
"Callable",
"<",
"T",
">",
"callable",
")",
"{",
"return",
"executorService",
".",
"submit",
"(",
"callable",
")",
";",
"}"
] | Schedules something for execution in the future. | [
"Schedules",
"something",
"for",
"execution",
"in",
"the",
"future",
"."
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/clientlibs/processor/ProcessorContext.java#L65-L67 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/core/util/RequestUtil.java | RequestUtil.getExtension | public static <T extends Enum> T getExtension(SlingHttpServletRequest request, T defaultValue) {
String extension = request.getRequestPathInfo().getExtension();
if (extension != null) {
Class type = defaultValue.getClass();
try {
T value = (T) T.valueOf(type, extension.toLowerCase());
return value;
} catch (IllegalArgumentException iaex) {
// ok, use default
}
}
return defaultValue;
} | java | public static <T extends Enum> T getExtension(SlingHttpServletRequest request, T defaultValue) {
String extension = request.getRequestPathInfo().getExtension();
if (extension != null) {
Class type = defaultValue.getClass();
try {
T value = (T) T.valueOf(type, extension.toLowerCase());
return value;
} catch (IllegalArgumentException iaex) {
// ok, use default
}
}
return defaultValue;
} | [
"public",
"static",
"<",
"T",
"extends",
"Enum",
">",
"T",
"getExtension",
"(",
"SlingHttpServletRequest",
"request",
",",
"T",
"defaultValue",
")",
"{",
"String",
"extension",
"=",
"request",
".",
"getRequestPathInfo",
"(",
")",
".",
"getExtension",
"(",
")",... | Returns the enum value of the requests extension if appropriate otherwise the default value.
@param request the request object with the extension info
@param defaultValue the default enum value
@param <T> the enum type derived from the default value | [
"Returns",
"the",
"enum",
"value",
"of",
"the",
"requests",
"extension",
"if",
"appropriate",
"otherwise",
"the",
"default",
"value",
"."
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/core/util/RequestUtil.java#L31-L43 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/core/util/RequestUtil.java | RequestUtil.getSelector | public static <T extends Enum> T getSelector(SlingHttpServletRequest request, T defaultValue) {
String[] selectors = request.getRequestPathInfo().getSelectors();
Class type = defaultValue.getClass();
for (String selector : selectors) {
try {
T value = (T) T.valueOf(type, selector);
return value;
} catch (IllegalArgumentException iaex) {
// ok, try next
}
}
return defaultValue;
} | java | public static <T extends Enum> T getSelector(SlingHttpServletRequest request, T defaultValue) {
String[] selectors = request.getRequestPathInfo().getSelectors();
Class type = defaultValue.getClass();
for (String selector : selectors) {
try {
T value = (T) T.valueOf(type, selector);
return value;
} catch (IllegalArgumentException iaex) {
// ok, try next
}
}
return defaultValue;
} | [
"public",
"static",
"<",
"T",
"extends",
"Enum",
">",
"T",
"getSelector",
"(",
"SlingHttpServletRequest",
"request",
",",
"T",
"defaultValue",
")",
"{",
"String",
"[",
"]",
"selectors",
"=",
"request",
".",
"getRequestPathInfo",
"(",
")",
".",
"getSelectors",
... | Returns an enum value from selectors if an appropriate selector
can be found otherwise the default value given.
@param request the request object with the selector info
@param defaultValue the default enum value
@param <T> the enum type derived from the default value | [
"Returns",
"an",
"enum",
"value",
"from",
"selectors",
"if",
"an",
"appropriate",
"selector",
"can",
"be",
"found",
"otherwise",
"the",
"default",
"value",
"given",
"."
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/core/util/RequestUtil.java#L53-L65 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/core/util/RequestUtil.java | RequestUtil.checkSelector | public static boolean checkSelector(SlingHttpServletRequest request, String key) {
String[] selectors = request.getRequestPathInfo().getSelectors();
for (String selector : selectors) {
if (selector.equals(key)) {
return true;
}
}
return false;
} | java | public static boolean checkSelector(SlingHttpServletRequest request, String key) {
String[] selectors = request.getRequestPathInfo().getSelectors();
for (String selector : selectors) {
if (selector.equals(key)) {
return true;
}
}
return false;
} | [
"public",
"static",
"boolean",
"checkSelector",
"(",
"SlingHttpServletRequest",
"request",
",",
"String",
"key",
")",
"{",
"String",
"[",
"]",
"selectors",
"=",
"request",
".",
"getRequestPathInfo",
"(",
")",
".",
"getSelectors",
"(",
")",
";",
"for",
"(",
"... | Retrieves a key in the selectors and returns 'true' is the key is present.
@param request the request object with the selector info
@param key the selector key which is checked | [
"Retrieves",
"a",
"key",
"in",
"the",
"selectors",
"and",
"returns",
"true",
"is",
"the",
"key",
"is",
"present",
"."
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/core/util/RequestUtil.java#L73-L81 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/cpnl/CpnlBodyTagSupport.java | CpnlBodyTagSupport.getExpressionUtil | protected com.composum.sling.core.util.ExpressionUtil getExpressionUtil() {
if (expressionUtil == null) {
expressionUtil = new ExpressionUtil(pageContext);
}
return expressionUtil;
} | java | protected com.composum.sling.core.util.ExpressionUtil getExpressionUtil() {
if (expressionUtil == null) {
expressionUtil = new ExpressionUtil(pageContext);
}
return expressionUtil;
} | [
"protected",
"com",
".",
"composum",
".",
"sling",
".",
"core",
".",
"util",
".",
"ExpressionUtil",
"getExpressionUtil",
"(",
")",
"{",
"if",
"(",
"expressionUtil",
"==",
"null",
")",
"{",
"expressionUtil",
"=",
"new",
"ExpressionUtil",
"(",
"pageContext",
"... | Returns or creates the expressionUtil . Not null. | [
"Returns",
"or",
"creates",
"the",
"expressionUtil",
".",
"Not",
"null",
"."
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/cpnl/CpnlBodyTagSupport.java#L90-L95 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/core/InheritedValues.java | InheritedValues.findOriginAndValue | public HierarchyScanResult findOriginAndValue(String name, Class<?> type) {
Object value;
findEntryPoint();
String path = getRelativePath(name);
for (Resource parent = entryPoint; parent != null; parent = parent.getParent()) {
ValueMap parentProps = parent.adaptTo(ValueMap.class);
if (parentProps != null) {
value = parentProps.get(path, type);
if (value != null) {
return new HierarchyScanResult(parent, value);
}
}
if (exitPoint != null && parent.getPath().equals(exitPoint.getPath())) {
break;
}
}
return null;
} | java | public HierarchyScanResult findOriginAndValue(String name, Class<?> type) {
Object value;
findEntryPoint();
String path = getRelativePath(name);
for (Resource parent = entryPoint; parent != null; parent = parent.getParent()) {
ValueMap parentProps = parent.adaptTo(ValueMap.class);
if (parentProps != null) {
value = parentProps.get(path, type);
if (value != null) {
return new HierarchyScanResult(parent, value);
}
}
if (exitPoint != null && parent.getPath().equals(exitPoint.getPath())) {
break;
}
}
return null;
} | [
"public",
"HierarchyScanResult",
"findOriginAndValue",
"(",
"String",
"name",
",",
"Class",
"<",
"?",
">",
"type",
")",
"{",
"Object",
"value",
";",
"findEntryPoint",
"(",
")",
";",
"String",
"path",
"=",
"getRelativePath",
"(",
"name",
")",
";",
"for",
"(... | Searches the value along the repositories hierarchy by the entry point and path determined before.
@param name the property name or path
@param type the expected type of the value
@return the value found or <code>null</code> if no such value found
in one of the appropriate parent nodes | [
"Searches",
"the",
"value",
"along",
"the",
"repositories",
"hierarchy",
"by",
"the",
"entry",
"point",
"and",
"path",
"determined",
"before",
"."
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/core/InheritedValues.java#L155-L172 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/clientlibs/handle/ClientlibLink.java | ClientlibLink.withHash | public ClientlibLink withHash(String newHash) {
return new ClientlibLink(type, kind, path, properties, newHash);
} | java | public ClientlibLink withHash(String newHash) {
return new ClientlibLink(type, kind, path, properties, newHash);
} | [
"public",
"ClientlibLink",
"withHash",
"(",
"String",
"newHash",
")",
"{",
"return",
"new",
"ClientlibLink",
"(",
"type",
",",
"kind",
",",
"path",
",",
"properties",
",",
"newHash",
")",
";",
"}"
] | Creates a new link with parameters as this except hash.
@param newHash new nullable hash for the resource to be encoded in the URL for clientlibs / - categories. | [
"Creates",
"a",
"new",
"link",
"with",
"parameters",
"as",
"this",
"except",
"hash",
"."
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/clientlibs/handle/ClientlibLink.java#L103-L105 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/clientlibs/processor/UpdateTimeVisitor.java | UpdateTimeVisitor.getLastUpdateTime | public Calendar getLastUpdateTime() {
if (null != lastUpdateTime && lastUpdateTime.after(Calendar.getInstance())) {
LOG.warn("Last update time newer than now {} for {}", lastUpdateTime, owner);
return null; // Something's broken - we don't know
}
return lastUpdateTime;
} | java | public Calendar getLastUpdateTime() {
if (null != lastUpdateTime && lastUpdateTime.after(Calendar.getInstance())) {
LOG.warn("Last update time newer than now {} for {}", lastUpdateTime, owner);
return null; // Something's broken - we don't know
}
return lastUpdateTime;
} | [
"public",
"Calendar",
"getLastUpdateTime",
"(",
")",
"{",
"if",
"(",
"null",
"!=",
"lastUpdateTime",
"&&",
"lastUpdateTime",
".",
"after",
"(",
"Calendar",
".",
"getInstance",
"(",
")",
")",
")",
"{",
"LOG",
".",
"warn",
"(",
"\"Last update time newer than now... | Returns the last update time estimated from the file update times and clientlib folder create times.
This is only a lower bound for the update time of the client library including its embedded files. | [
"Returns",
"the",
"last",
"update",
"time",
"estimated",
"from",
"the",
"file",
"update",
"times",
"and",
"clientlib",
"folder",
"create",
"times",
".",
"This",
"is",
"only",
"a",
"lower",
"bound",
"for",
"the",
"update",
"time",
"of",
"the",
"client",
"li... | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/clientlibs/processor/UpdateTimeVisitor.java#L43-L49 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/clientlibs/servlet/ClientlibServlet.java | ClientlibServlet.appendHashSuffix | public static String appendHashSuffix(String url, String hash) {
if (null == hash) return url;
Matcher matcher = FILENAME_PATTERN.matcher(url);
String fname = "";
if (matcher.find()) fname = matcher.group(0);
return url + "/" + hash + "/" + fname;
} | java | public static String appendHashSuffix(String url, String hash) {
if (null == hash) return url;
Matcher matcher = FILENAME_PATTERN.matcher(url);
String fname = "";
if (matcher.find()) fname = matcher.group(0);
return url + "/" + hash + "/" + fname;
} | [
"public",
"static",
"String",
"appendHashSuffix",
"(",
"String",
"url",
",",
"String",
"hash",
")",
"{",
"if",
"(",
"null",
"==",
"hash",
")",
"return",
"url",
";",
"Matcher",
"matcher",
"=",
"FILENAME_PATTERN",
".",
"matcher",
"(",
"url",
")",
";",
"Str... | Appends a suffix containing the hash code, if given. The file name is repeated to satisfy browsers
with the correct type and file name, though it is not used by the servlet.
@param url an url to which we append the suffix
@param hash optional, the hash code
@return the url with suffix /{hash}/{filename} appended, where {filename} is the last part of a / separated url. | [
"Appends",
"a",
"suffix",
"containing",
"the",
"hash",
"code",
"if",
"given",
".",
"The",
"file",
"name",
"is",
"repeated",
"to",
"satisfy",
"browsers",
"with",
"the",
"correct",
"type",
"and",
"file",
"name",
"though",
"it",
"is",
"not",
"used",
"by",
"... | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/clientlibs/servlet/ClientlibServlet.java#L86-L92 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/clientlibs/processor/RendererContext.java | RendererContext.isClientlibRendered | public boolean isClientlibRendered(ClientlibRef reference) {
for (ClientlibLink link : renderedClientlibs) {
if (reference.isSatisfiedby(link)) {
LOG.debug("already rendered: {} by {}", reference, link.path);
return true;
}
}
return false;
} | java | public boolean isClientlibRendered(ClientlibRef reference) {
for (ClientlibLink link : renderedClientlibs) {
if (reference.isSatisfiedby(link)) {
LOG.debug("already rendered: {} by {}", reference, link.path);
return true;
}
}
return false;
} | [
"public",
"boolean",
"isClientlibRendered",
"(",
"ClientlibRef",
"reference",
")",
"{",
"for",
"(",
"ClientlibLink",
"link",
":",
"renderedClientlibs",
")",
"{",
"if",
"(",
"reference",
".",
"isSatisfiedby",
"(",
"link",
")",
")",
"{",
"LOG",
".",
"debug",
"... | Checks whether a referenced resource or client library is satisfied by an already rendered resource. | [
"Checks",
"whether",
"a",
"referenced",
"resource",
"or",
"client",
"library",
"is",
"satisfied",
"by",
"an",
"already",
"rendered",
"resource",
"."
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/clientlibs/processor/RendererContext.java#L49-L57 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/cpnl/ComponentTag.java | ComponentTag.getComponentType | protected Class<? extends SlingBean> getComponentType() throws ClassNotFoundException {
if (componentType == null) {
String type = getType();
if (StringUtils.isNotBlank(type)) {
componentType = (Class<? extends SlingBean>) context.getType(type);
}
}
return componentType;
} | java | protected Class<? extends SlingBean> getComponentType() throws ClassNotFoundException {
if (componentType == null) {
String type = getType();
if (StringUtils.isNotBlank(type)) {
componentType = (Class<? extends SlingBean>) context.getType(type);
}
}
return componentType;
} | [
"protected",
"Class",
"<",
"?",
"extends",
"SlingBean",
">",
"getComponentType",
"(",
")",
"throws",
"ClassNotFoundException",
"{",
"if",
"(",
"componentType",
"==",
"null",
")",
"{",
"String",
"type",
"=",
"getType",
"(",
")",
";",
"if",
"(",
"StringUtils",... | get the content type class object | [
"get",
"the",
"content",
"type",
"class",
"object"
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/cpnl/ComponentTag.java#L152-L160 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/cpnl/ComponentTag.java | ComponentTag.available | protected Object available() throws ClassNotFoundException {
Object result = null;
if (getVar() != null) {
Object value = pageContext.getAttribute(getVar(), getVarScope());
if (value instanceof SlingBean) {
Class<?> type = getComponentType();
if (type != null && type.isAssignableFrom(value.getClass())) {
result = value;
}
}
}
return result;
} | java | protected Object available() throws ClassNotFoundException {
Object result = null;
if (getVar() != null) {
Object value = pageContext.getAttribute(getVar(), getVarScope());
if (value instanceof SlingBean) {
Class<?> type = getComponentType();
if (type != null && type.isAssignableFrom(value.getClass())) {
result = value;
}
}
}
return result;
} | [
"protected",
"Object",
"available",
"(",
")",
"throws",
"ClassNotFoundException",
"{",
"Object",
"result",
"=",
"null",
";",
"if",
"(",
"getVar",
"(",
")",
"!=",
"null",
")",
"{",
"Object",
"value",
"=",
"pageContext",
".",
"getAttribute",
"(",
"getVar",
"... | Check for an existing instance of the same var and assignable type | [
"Check",
"for",
"an",
"existing",
"instance",
"of",
"the",
"same",
"var",
"and",
"assignable",
"type"
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/cpnl/ComponentTag.java#L165-L177 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/cpnl/ComponentTag.java | ComponentTag.createComponent | protected SlingBean createComponent() throws ClassNotFoundException, IllegalAccessException,
InstantiationException {
SlingBean component = null;
Class<? extends SlingBean> type = getComponentType();
if (type != null) {
BeanFactory factoryRule = type.getAnnotation(BeanFactory.class);
if (factoryRule != null) {
SlingBeanFactory factory = context.getService(factoryRule.serviceClass());
if (factory != null) {
return factory.createBean(context, getModelResource(context), type);
}
}
BeanContext baseContext = context.withResource(getModelResource(context));
component = baseContext.adaptTo(type);
injectServices(component);
additionalInitialization(component);
}
return component;
} | java | protected SlingBean createComponent() throws ClassNotFoundException, IllegalAccessException,
InstantiationException {
SlingBean component = null;
Class<? extends SlingBean> type = getComponentType();
if (type != null) {
BeanFactory factoryRule = type.getAnnotation(BeanFactory.class);
if (factoryRule != null) {
SlingBeanFactory factory = context.getService(factoryRule.serviceClass());
if (factory != null) {
return factory.createBean(context, getModelResource(context), type);
}
}
BeanContext baseContext = context.withResource(getModelResource(context));
component = baseContext.adaptTo(type);
injectServices(component);
additionalInitialization(component);
}
return component;
} | [
"protected",
"SlingBean",
"createComponent",
"(",
")",
"throws",
"ClassNotFoundException",
",",
"IllegalAccessException",
",",
"InstantiationException",
"{",
"SlingBean",
"component",
"=",
"null",
";",
"Class",
"<",
"?",
"extends",
"SlingBean",
">",
"type",
"=",
"ge... | Create the requested component instance | [
"Create",
"the",
"requested",
"component",
"instance"
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/cpnl/ComponentTag.java#L182-L200 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/cpnl/ComponentTag.java | ComponentTag.getReplacedAttributes | protected Map<String, Object> getReplacedAttributes(int scope) {
if (replacedAttributes == null) {
replacedAttributes = new ArrayList<>();
}
while (replacedAttributes.size() <= scope) {
replacedAttributes.add(new HashMap<String, Object>());
}
return replacedAttributes.get(scope);
} | java | protected Map<String, Object> getReplacedAttributes(int scope) {
if (replacedAttributes == null) {
replacedAttributes = new ArrayList<>();
}
while (replacedAttributes.size() <= scope) {
replacedAttributes.add(new HashMap<String, Object>());
}
return replacedAttributes.get(scope);
} | [
"protected",
"Map",
"<",
"String",
",",
"Object",
">",
"getReplacedAttributes",
"(",
"int",
"scope",
")",
"{",
"if",
"(",
"replacedAttributes",
"==",
"null",
")",
"{",
"replacedAttributes",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"}",
"while",
"(",
... | retrieves the registry for one scope | [
"retrieves",
"the",
"registry",
"for",
"one",
"scope"
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/cpnl/ComponentTag.java#L268-L276 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/cpnl/ComponentTag.java | ComponentTag.setAttribute | protected void setAttribute(String key, Object value, int scope) {
Map<String, Object> replacedInScope = getReplacedAttributes(scope);
if (!replacedInScope.containsKey(key)) {
Object current = pageContext.getAttribute(key, scope);
replacedInScope.put(key, current);
}
pageContext.setAttribute(key, value, scope);
} | java | protected void setAttribute(String key, Object value, int scope) {
Map<String, Object> replacedInScope = getReplacedAttributes(scope);
if (!replacedInScope.containsKey(key)) {
Object current = pageContext.getAttribute(key, scope);
replacedInScope.put(key, current);
}
pageContext.setAttribute(key, value, scope);
} | [
"protected",
"void",
"setAttribute",
"(",
"String",
"key",
",",
"Object",
"value",
",",
"int",
"scope",
")",
"{",
"Map",
"<",
"String",
",",
"Object",
">",
"replacedInScope",
"=",
"getReplacedAttributes",
"(",
"scope",
")",
";",
"if",
"(",
"!",
"replacedIn... | each attribute set by a tag should use this method for attribute declaration;
an existing value with the same key is registered and restored if the tag rendering ends | [
"each",
"attribute",
"set",
"by",
"a",
"tag",
"should",
"use",
"this",
"method",
"for",
"attribute",
"declaration",
";",
"an",
"existing",
"value",
"with",
"the",
"same",
"key",
"is",
"registered",
"and",
"restored",
"if",
"the",
"tag",
"rendering",
"ends"
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/cpnl/ComponentTag.java#L282-L289 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/cpnl/ComponentTag.java | ComponentTag.restoreAttributes | protected void restoreAttributes() {
if (replacedAttributes != null) {
for (int scope = 0; scope < replacedAttributes.size(); scope++) {
Map<String, Object> replaced = replacedAttributes.get(scope);
for (Map.Entry<String, Object> entry : replaced.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
if (value != null) {
pageContext.setAttribute(key, value, scope);
} else {
pageContext.removeAttribute(key, scope);
}
}
}
}
} | java | protected void restoreAttributes() {
if (replacedAttributes != null) {
for (int scope = 0; scope < replacedAttributes.size(); scope++) {
Map<String, Object> replaced = replacedAttributes.get(scope);
for (Map.Entry<String, Object> entry : replaced.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
if (value != null) {
pageContext.setAttribute(key, value, scope);
} else {
pageContext.removeAttribute(key, scope);
}
}
}
}
} | [
"protected",
"void",
"restoreAttributes",
"(",
")",
"{",
"if",
"(",
"replacedAttributes",
"!=",
"null",
")",
"{",
"for",
"(",
"int",
"scope",
"=",
"0",
";",
"scope",
"<",
"replacedAttributes",
".",
"size",
"(",
")",
";",
"scope",
"++",
")",
"{",
"Map",... | restores all replaced values and removes all attributes declared in this tag | [
"restores",
"all",
"replaced",
"values",
"and",
"removes",
"all",
"attributes",
"declared",
"in",
"this",
"tag"
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/cpnl/ComponentTag.java#L294-L309 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/core/servlet/ServletOperationSet.java | ServletOperationSet.getOperation | public ServletOperation getOperation(SlingHttpServletRequest request, Method method) {
ServletOperation operation = null;
E extension = RequestUtil.getExtension(request, defaultExtension);
Map<E, O> extensionDefaults = operationDefaults.get(method);
if (extensionDefaults != null) {
O defaultOperation = extensionDefaults.get(extension);
if (defaultOperation != null) {
Map<E, Map<O, ServletOperation>> extensions = operationMap.get(method);
if (extensions != null) {
Map<O, ServletOperation> operations = extensions.get(extension);
if (operations != null) {
operation = operations.get(RequestUtil.getSelector(request, defaultOperation));
}
}
}
}
return operation;
} | java | public ServletOperation getOperation(SlingHttpServletRequest request, Method method) {
ServletOperation operation = null;
E extension = RequestUtil.getExtension(request, defaultExtension);
Map<E, O> extensionDefaults = operationDefaults.get(method);
if (extensionDefaults != null) {
O defaultOperation = extensionDefaults.get(extension);
if (defaultOperation != null) {
Map<E, Map<O, ServletOperation>> extensions = operationMap.get(method);
if (extensions != null) {
Map<O, ServletOperation> operations = extensions.get(extension);
if (operations != null) {
operation = operations.get(RequestUtil.getSelector(request, defaultOperation));
}
}
}
}
return operation;
} | [
"public",
"ServletOperation",
"getOperation",
"(",
"SlingHttpServletRequest",
"request",
",",
"Method",
"method",
")",
"{",
"ServletOperation",
"operation",
"=",
"null",
";",
"E",
"extension",
"=",
"RequestUtil",
".",
"getExtension",
"(",
"request",
",",
"defaultExt... | Retrieves the servlet operation requested for the used HTTP method.
Looks in the selectors for a operation and gives their implementation in the extensions context.
@param request the servlet request
@param method the requested HTTP method
@return the operation or 'null', if the requested combination of selector
and extension has no implementation for the given HTTP method | [
"Retrieves",
"the",
"servlet",
"operation",
"requested",
"for",
"the",
"used",
"HTTP",
"method",
".",
"Looks",
"in",
"the",
"selectors",
"for",
"a",
"operation",
"and",
"gives",
"their",
"implementation",
"in",
"the",
"extensions",
"context",
"."
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/core/servlet/ServletOperationSet.java#L51-L68 | train |
ist-dresden/composum | sling/core/console/src/main/java/com/composum/sling/nodes/servlet/NodeServlet.java | NodeServlet.bindFilterConfiguration | protected synchronized void bindFilterConfiguration(final FilterConfiguration config) {
if (filterConfigurations == null) {
filterConfigurations = new ArrayList<>();
}
filterConfigurations.add(config);
String key = config.getName();
ResourceFilter filter = config.getFilter();
if (StringUtils.isNotBlank(key) && filter != null) {
nodeFilters.put(key, buildTreeFilter(filter));
}
} | java | protected synchronized void bindFilterConfiguration(final FilterConfiguration config) {
if (filterConfigurations == null) {
filterConfigurations = new ArrayList<>();
}
filterConfigurations.add(config);
String key = config.getName();
ResourceFilter filter = config.getFilter();
if (StringUtils.isNotBlank(key) && filter != null) {
nodeFilters.put(key, buildTreeFilter(filter));
}
} | [
"protected",
"synchronized",
"void",
"bindFilterConfiguration",
"(",
"final",
"FilterConfiguration",
"config",
")",
"{",
"if",
"(",
"filterConfigurations",
"==",
"null",
")",
"{",
"filterConfigurations",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"}",
"filterCo... | for each configured filter in the OSGi configuration
a tree filter is added to the filter set
@param config the OSGi filter configuration object | [
"for",
"each",
"configured",
"filter",
"in",
"the",
"OSGi",
"configuration",
"a",
"tree",
"filter",
"is",
"added",
"to",
"the",
"filter",
"set"
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/console/src/main/java/com/composum/sling/nodes/servlet/NodeServlet.java#L130-L140 | train |
ist-dresden/composum | sling/core/console/src/main/java/com/composum/sling/nodes/servlet/NodeServlet.java | NodeServlet.unbindFilterConfiguration | protected synchronized void unbindFilterConfiguration(final FilterConfiguration config) {
nodeFilters.remove(config.getName());
filterConfigurations.remove(config);
} | java | protected synchronized void unbindFilterConfiguration(final FilterConfiguration config) {
nodeFilters.remove(config.getName());
filterConfigurations.remove(config);
} | [
"protected",
"synchronized",
"void",
"unbindFilterConfiguration",
"(",
"final",
"FilterConfiguration",
"config",
")",
"{",
"nodeFilters",
".",
"remove",
"(",
"config",
".",
"getName",
"(",
")",
")",
";",
"filterConfigurations",
".",
"remove",
"(",
"config",
")",
... | removing of a configuration which is not longer available;
removes the corresponding tree filter also
@param config the OSGi filter configuration object to remove | [
"removing",
"of",
"a",
"configuration",
"which",
"is",
"not",
"longer",
"available",
";",
"removes",
"the",
"corresponding",
"tree",
"filter",
"also"
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/console/src/main/java/com/composum/sling/nodes/servlet/NodeServlet.java#L148-L151 | train |
ist-dresden/composum | sling/core/console/src/main/java/com/composum/sling/nodes/servlet/NodeServlet.java | NodeServlet.getNodeFilter | protected ResourceFilter getNodeFilter(SlingHttpServletRequest request) {
ResourceFilter filter = null;
String filterParam = RequestUtil.getParameter(request, PARAM_FILTER, (String) null);
if (StringUtils.isNotBlank(filterParam)) {
filter = nodeFilters.get(filterParam);
}
if (filter == null) {
RequestPathInfo pathInfo = request.getRequestPathInfo();
for (String selector : pathInfo.getSelectors()) {
filter = nodeFilters.get(selector);
if (filter != null) {
break;
}
}
}
if (filter == null) {
filter = nodesConfig.getDefaultNodeFilter();
}
return filter;
} | java | protected ResourceFilter getNodeFilter(SlingHttpServletRequest request) {
ResourceFilter filter = null;
String filterParam = RequestUtil.getParameter(request, PARAM_FILTER, (String) null);
if (StringUtils.isNotBlank(filterParam)) {
filter = nodeFilters.get(filterParam);
}
if (filter == null) {
RequestPathInfo pathInfo = request.getRequestPathInfo();
for (String selector : pathInfo.getSelectors()) {
filter = nodeFilters.get(selector);
if (filter != null) {
break;
}
}
}
if (filter == null) {
filter = nodesConfig.getDefaultNodeFilter();
}
return filter;
} | [
"protected",
"ResourceFilter",
"getNodeFilter",
"(",
"SlingHttpServletRequest",
"request",
")",
"{",
"ResourceFilter",
"filter",
"=",
"null",
";",
"String",
"filterParam",
"=",
"RequestUtil",
".",
"getParameter",
"(",
"request",
",",
"PARAM_FILTER",
",",
"(",
"Strin... | Determines the filter to use for node retrieval; scans the request for filter parameter or selector. | [
"Determines",
"the",
"filter",
"to",
"use",
"for",
"node",
"retrieval",
";",
"scans",
"the",
"request",
"for",
"filter",
"parameter",
"or",
"selector",
"."
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/console/src/main/java/com/composum/sling/nodes/servlet/NodeServlet.java#L172-L191 | train |
ist-dresden/composum | sling/core/console/src/main/java/com/composum/sling/nodes/servlet/NodeServlet.java | NodeServlet.prepareTreeItems | @Override
protected List<Resource> prepareTreeItems(ResourceHandle resource, List<Resource> items) {
if (!nodesConfig.getOrderableNodesFilter().accept(resource)) {
Collections.sort(items, new Comparator<Resource>() {
@Override
public int compare(Resource r1, Resource r2) {
return getSortName(r1).compareTo(getSortName(r2));
}
});
}
return items;
} | java | @Override
protected List<Resource> prepareTreeItems(ResourceHandle resource, List<Resource> items) {
if (!nodesConfig.getOrderableNodesFilter().accept(resource)) {
Collections.sort(items, new Comparator<Resource>() {
@Override
public int compare(Resource r1, Resource r2) {
return getSortName(r1).compareTo(getSortName(r2));
}
});
}
return items;
} | [
"@",
"Override",
"protected",
"List",
"<",
"Resource",
">",
"prepareTreeItems",
"(",
"ResourceHandle",
"resource",
",",
"List",
"<",
"Resource",
">",
"items",
")",
"{",
"if",
"(",
"!",
"nodesConfig",
".",
"getOrderableNodesFilter",
"(",
")",
".",
"accept",
"... | sort children of orderable nodes | [
"sort",
"children",
"of",
"orderable",
"nodes"
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/console/src/main/java/com/composum/sling/nodes/servlet/NodeServlet.java#L597-L608 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/core/config/FilterConfigurationImpl.java | FilterConfigurationImpl.activate | @Activate
protected void activate(ComponentContext context) {
Dictionary properties = context.getProperties();
name = (String) properties.get("name");
filter = ResourceFilterMapping.fromString((String) properties.get("filter"));
} | java | @Activate
protected void activate(ComponentContext context) {
Dictionary properties = context.getProperties();
name = (String) properties.get("name");
filter = ResourceFilterMapping.fromString((String) properties.get("filter"));
} | [
"@",
"Activate",
"protected",
"void",
"activate",
"(",
"ComponentContext",
"context",
")",
"{",
"Dictionary",
"properties",
"=",
"context",
".",
"getProperties",
"(",
")",
";",
"name",
"=",
"(",
"String",
")",
"properties",
".",
"get",
"(",
"\"name\"",
")",
... | creates the filter instance for the configured rule | [
"creates",
"the",
"filter",
"instance",
"for",
"the",
"configured",
"rule"
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/core/config/FilterConfigurationImpl.java#L59-L64 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/core/servlet/AbstractServiceServlet.java | AbstractServiceServlet.getResource | public static ResourceHandle getResource(SlingHttpServletRequest request) {
ResourceResolver resolver = request.getResourceResolver();
String path = getPath(request);
ResourceHandle resource = ResourceHandle.use(resolver.resolve(path));
return resource;
} | java | public static ResourceHandle getResource(SlingHttpServletRequest request) {
ResourceResolver resolver = request.getResourceResolver();
String path = getPath(request);
ResourceHandle resource = ResourceHandle.use(resolver.resolve(path));
return resource;
} | [
"public",
"static",
"ResourceHandle",
"getResource",
"(",
"SlingHttpServletRequest",
"request",
")",
"{",
"ResourceResolver",
"resolver",
"=",
"request",
".",
"getResourceResolver",
"(",
")",
";",
"String",
"path",
"=",
"getPath",
"(",
"request",
")",
";",
"Resour... | Retrieves the resource using the suffix from the request.
@param request the sling request with the resource path in the suffix
@return the resource (NOT <code>null</code>; returns a handle with an invalid resource if not resolvable) | [
"Retrieves",
"the",
"resource",
"using",
"the",
"suffix",
"from",
"the",
"request",
"."
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/core/servlet/AbstractServiceServlet.java#L141-L146 | train |
ist-dresden/composum | sling/core/commons/src/main/java/com/composum/sling/core/util/ConsoleUtil.java | ConsoleUtil.getConsoleResource | public static Resource getConsoleResource(BeanContext context) {
SlingHttpServletRequest request = context.getRequest();
ResourceResolver resolver = request.getResourceResolver();
String path = null;
// use the resource set by a probably executed 'defineObjects' tag (supports including components)
Resource resource = context.getAttribute("resource", Resource.class);
if (resource == null) {
resource = request.getResource();
}
if (resource != null) {
path = resource.getPath();
}
// use the suffix as the resource path if the resource is not defined or references a servlet
if (StringUtils.isBlank(path) || path.startsWith("/bin/")) {
RequestPathInfo requestPathInfo = request.getRequestPathInfo();
path = requestPathInfo.getSuffix();
resource = null;
}
if (resource == null && StringUtils.isNotBlank(path)) {
resource = resolver.getResource(path);
}
if (resource == null) {
// fallback to the root node if the servlet request has no suffix
resource = resolver.getResource("/");
}
return resource;
} | java | public static Resource getConsoleResource(BeanContext context) {
SlingHttpServletRequest request = context.getRequest();
ResourceResolver resolver = request.getResourceResolver();
String path = null;
// use the resource set by a probably executed 'defineObjects' tag (supports including components)
Resource resource = context.getAttribute("resource", Resource.class);
if (resource == null) {
resource = request.getResource();
}
if (resource != null) {
path = resource.getPath();
}
// use the suffix as the resource path if the resource is not defined or references a servlet
if (StringUtils.isBlank(path) || path.startsWith("/bin/")) {
RequestPathInfo requestPathInfo = request.getRequestPathInfo();
path = requestPathInfo.getSuffix();
resource = null;
}
if (resource == null && StringUtils.isNotBlank(path)) {
resource = resolver.getResource(path);
}
if (resource == null) {
// fallback to the root node if the servlet request has no suffix
resource = resolver.getResource("/");
}
return resource;
} | [
"public",
"static",
"Resource",
"getConsoleResource",
"(",
"BeanContext",
"context",
")",
"{",
"SlingHttpServletRequest",
"request",
"=",
"context",
".",
"getRequest",
"(",
")",
";",
"ResourceResolver",
"resolver",
"=",
"request",
".",
"getResourceResolver",
"(",
")... | determines the addressed resource by the suffix if the requests resource is the servlet itself | [
"determines",
"the",
"addressed",
"resource",
"by",
"the",
"suffix",
"if",
"the",
"requests",
"resource",
"is",
"the",
"servlet",
"itself"
] | ebc79f559f6022c935240c19102539bdfb1bd1e2 | https://github.com/ist-dresden/composum/blob/ebc79f559f6022c935240c19102539bdfb1bd1e2/sling/core/commons/src/main/java/com/composum/sling/core/util/ConsoleUtil.java#L16-L42 | train |
bazaarvoice/emodb | sor-api/src/main/java/com/bazaarvoice/emodb/sor/delta/impl/LiteralImpl.java | LiteralImpl.areClassesEqual | private boolean areClassesEqual(Class<?> c1, Class<?> c2) {
if (isMap(c1)) {
return isMap(c2);
} else if (isList(c1)) {
return isList(c2);
} else {
return c1.equals(c2);
}
} | java | private boolean areClassesEqual(Class<?> c1, Class<?> c2) {
if (isMap(c1)) {
return isMap(c2);
} else if (isList(c1)) {
return isList(c2);
} else {
return c1.equals(c2);
}
} | [
"private",
"boolean",
"areClassesEqual",
"(",
"Class",
"<",
"?",
">",
"c1",
",",
"Class",
"<",
"?",
">",
"c2",
")",
"{",
"if",
"(",
"isMap",
"(",
"c1",
")",
")",
"{",
"return",
"isMap",
"(",
"c2",
")",
";",
"}",
"else",
"if",
"(",
"isList",
"("... | When comparing literals allow subclasses of Maps and Lists to be directly compared even if they have
different implementations. | [
"When",
"comparing",
"literals",
"allow",
"subclasses",
"of",
"Maps",
"and",
"Lists",
"to",
"be",
"directly",
"compared",
"even",
"if",
"they",
"have",
"different",
"implementations",
"."
] | 97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb | https://github.com/bazaarvoice/emodb/blob/97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb/sor-api/src/main/java/com/bazaarvoice/emodb/sor/delta/impl/LiteralImpl.java#L139-L147 | train |
bazaarvoice/emodb | web/src/main/java/com/bazaarvoice/emodb/web/auth/EmoPermission.java | EmoPermission.toPart | @Override
protected MatchingPart toPart(List<MatchingPart> leadingParts, String part) {
switch (leadingParts.size()) {
case 0:
// The first part must either be a constant or a pure wildcard; expressions such as
// <code>if(or("sor","blob"))</code> are not permitted.
MatchingPart resolvedPart = createEmoPermissionPart(part, PartType.CONTEXT);
checkArgument(resolvedPart instanceof ConstantPart || resolvedPart.impliesAny(),
"First part must be a constant or pure wildcard");
return resolvedPart;
case 1:
// If the first part was a pure wildcard then there cannot be a second part; expressions such as
// "*|create_table" are not permitted.
checkArgument(!MatchingPart.getContext(leadingParts).impliesAny(), "Cannot narrow permission without initial scope");
return createEmoPermissionPart(part, PartType.ACTION);
case 2:
// For sor and blob permissions the third part narrows to a table. Otherwise it narrows to a
// named resource such as a queue name or databus subscription.
PartType partType;
if (MatchingPart.contextImpliedBy(SOR_PART, leadingParts)) {
partType = PartType.SOR_TABLE;
} else if (MatchingPart.contextImpliedBy(BLOB_PART, leadingParts)) {
partType = PartType.BLOB_TABLE;
} else {
partType = PartType.NAMED_RESOURCE;
}
return createEmoPermissionPart(part, partType);
case 3:
// Only roles support four parts, where the group is the third part and the role ID is the fourth part.
if (MatchingPart.contextImpliedBy(ROLE_PART, leadingParts)) {
return createEmoPermissionPart(part, PartType.NAMED_RESOURCE);
}
break;
}
throw new IllegalArgumentException(format("Too many parts for EmoPermission in \"%s\" context",
MatchingPart.getContext(leadingParts)));
} | java | @Override
protected MatchingPart toPart(List<MatchingPart> leadingParts, String part) {
switch (leadingParts.size()) {
case 0:
// The first part must either be a constant or a pure wildcard; expressions such as
// <code>if(or("sor","blob"))</code> are not permitted.
MatchingPart resolvedPart = createEmoPermissionPart(part, PartType.CONTEXT);
checkArgument(resolvedPart instanceof ConstantPart || resolvedPart.impliesAny(),
"First part must be a constant or pure wildcard");
return resolvedPart;
case 1:
// If the first part was a pure wildcard then there cannot be a second part; expressions such as
// "*|create_table" are not permitted.
checkArgument(!MatchingPart.getContext(leadingParts).impliesAny(), "Cannot narrow permission without initial scope");
return createEmoPermissionPart(part, PartType.ACTION);
case 2:
// For sor and blob permissions the third part narrows to a table. Otherwise it narrows to a
// named resource such as a queue name or databus subscription.
PartType partType;
if (MatchingPart.contextImpliedBy(SOR_PART, leadingParts)) {
partType = PartType.SOR_TABLE;
} else if (MatchingPart.contextImpliedBy(BLOB_PART, leadingParts)) {
partType = PartType.BLOB_TABLE;
} else {
partType = PartType.NAMED_RESOURCE;
}
return createEmoPermissionPart(part, partType);
case 3:
// Only roles support four parts, where the group is the third part and the role ID is the fourth part.
if (MatchingPart.contextImpliedBy(ROLE_PART, leadingParts)) {
return createEmoPermissionPart(part, PartType.NAMED_RESOURCE);
}
break;
}
throw new IllegalArgumentException(format("Too many parts for EmoPermission in \"%s\" context",
MatchingPart.getContext(leadingParts)));
} | [
"@",
"Override",
"protected",
"MatchingPart",
"toPart",
"(",
"List",
"<",
"MatchingPart",
">",
"leadingParts",
",",
"String",
"part",
")",
"{",
"switch",
"(",
"leadingParts",
".",
"size",
"(",
")",
")",
"{",
"case",
"0",
":",
"// The first part must either be ... | Override the logic in the parent to meet the requirements for EmoPermission. | [
"Override",
"the",
"logic",
"in",
"the",
"parent",
"to",
"meet",
"the",
"requirements",
"for",
"EmoPermission",
"."
] | 97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb | https://github.com/bazaarvoice/emodb/blob/97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb/web/src/main/java/com/bazaarvoice/emodb/web/auth/EmoPermission.java#L86-L126 | train |
bazaarvoice/emodb | web/src/main/java/com/bazaarvoice/emodb/web/auth/EmoPermission.java | EmoPermission.createEmoPermissionPart | private MatchingPart createEmoPermissionPart(String part, PartType partType) {
part = unescapeSeparators(part);
// Superclass guarantees part will be non-empty; no need to validate length prior to evaluating the first character
switch (part.charAt(0)) {
case 'c':
// "createTable" only applies to table resource parts
if (isTableResource(partType) && part.startsWith("createTable(") && part.endsWith(")")) {
String rison = part.substring(12, part.length() - 1);
return RisonHelper.fromORison(rison, CreateTablePart.class);
}
break;
case 'i':
if (part.startsWith("if(") && part.endsWith(")")) {
String condition = part.substring(3, part.length() - 1);
switch (partType) {
case SOR_TABLE:
return new SorTableConditionPart(Conditions.fromString(condition), _dataStore);
case BLOB_TABLE:
return new BlobTableConditionPart(Conditions.fromString(condition), _blobStore);
default:
return new ConditionPart(Conditions.fromString(condition));
}
}
break;
case '*':
if (part.length() == 1) {
// This is a pure wildcard
return getAnyPart();
}
break;
case '?':
if (part.length() == 1) {
// This is an "implied part exists" check
return EmoImpliedPartExistsPart.instance();
}
break;
}
// All other strings shortcuts for either a resource name or a wildcard expression for matching the name.
Condition condition = Conditions.like(part);
if (condition instanceof EqualCondition) {
return new EmoConstantPart(part);
}
return new ConditionPart(condition);
} | java | private MatchingPart createEmoPermissionPart(String part, PartType partType) {
part = unescapeSeparators(part);
// Superclass guarantees part will be non-empty; no need to validate length prior to evaluating the first character
switch (part.charAt(0)) {
case 'c':
// "createTable" only applies to table resource parts
if (isTableResource(partType) && part.startsWith("createTable(") && part.endsWith(")")) {
String rison = part.substring(12, part.length() - 1);
return RisonHelper.fromORison(rison, CreateTablePart.class);
}
break;
case 'i':
if (part.startsWith("if(") && part.endsWith(")")) {
String condition = part.substring(3, part.length() - 1);
switch (partType) {
case SOR_TABLE:
return new SorTableConditionPart(Conditions.fromString(condition), _dataStore);
case BLOB_TABLE:
return new BlobTableConditionPart(Conditions.fromString(condition), _blobStore);
default:
return new ConditionPart(Conditions.fromString(condition));
}
}
break;
case '*':
if (part.length() == 1) {
// This is a pure wildcard
return getAnyPart();
}
break;
case '?':
if (part.length() == 1) {
// This is an "implied part exists" check
return EmoImpliedPartExistsPart.instance();
}
break;
}
// All other strings shortcuts for either a resource name or a wildcard expression for matching the name.
Condition condition = Conditions.like(part);
if (condition instanceof EqualCondition) {
return new EmoConstantPart(part);
}
return new ConditionPart(condition);
} | [
"private",
"MatchingPart",
"createEmoPermissionPart",
"(",
"String",
"part",
",",
"PartType",
"partType",
")",
"{",
"part",
"=",
"unescapeSeparators",
"(",
"part",
")",
";",
"// Superclass guarantees part will be non-empty; no need to validate length prior to evaluating the first... | Creates a TableIdentificationPart for the third value in a data or blob store permission.
@param part String representation of the part
@param partType What type of part is being evaluated | [
"Creates",
"a",
"TableIdentificationPart",
"for",
"the",
"third",
"value",
"in",
"a",
"data",
"or",
"blob",
"store",
"permission",
"."
] | 97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb | https://github.com/bazaarvoice/emodb/blob/97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb/web/src/main/java/com/bazaarvoice/emodb/web/auth/EmoPermission.java#L133-L183 | train |
bazaarvoice/emodb | common/json/src/main/java/com/bazaarvoice/emodb/common/json/JsonStreamingArrayParser.java | JsonStreamingArrayParser.isJsonProcessingException | private boolean isJsonProcessingException(Exception e) {
// Unfortunately Jackson doesn't have specific subclasses for each parse exception, so we have to use the
// more brittle approach of checking the exception message.
return e instanceof JsonProcessingException &&
!(e instanceof JsonParseException &&
e.getMessage() != null &&
e.getMessage().startsWith("Unexpected end-of-input"));
} | java | private boolean isJsonProcessingException(Exception e) {
// Unfortunately Jackson doesn't have specific subclasses for each parse exception, so we have to use the
// more brittle approach of checking the exception message.
return e instanceof JsonProcessingException &&
!(e instanceof JsonParseException &&
e.getMessage() != null &&
e.getMessage().startsWith("Unexpected end-of-input"));
} | [
"private",
"boolean",
"isJsonProcessingException",
"(",
"Exception",
"e",
")",
"{",
"// Unfortunately Jackson doesn't have specific subclasses for each parse exception, so we have to use the",
"// more brittle approach of checking the exception message.",
"return",
"e",
"instanceof",
"Json... | Returns true if the exception is a JsonProcessingException whose root cause is not a premature end of data,
since this is more likely caused by a connection error. | [
"Returns",
"true",
"if",
"the",
"exception",
"is",
"a",
"JsonProcessingException",
"whose",
"root",
"cause",
"is",
"not",
"a",
"premature",
"end",
"of",
"data",
"since",
"this",
"is",
"more",
"likely",
"caused",
"by",
"a",
"connection",
"error",
"."
] | 97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb | https://github.com/bazaarvoice/emodb/blob/97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb/common/json/src/main/java/com/bazaarvoice/emodb/common/json/JsonStreamingArrayParser.java#L91-L98 | train |
bazaarvoice/emodb | common/zookeeper/src/main/java/com/bazaarvoice/emodb/common/zookeeper/Sync.java | Sync.synchronousSync | public static boolean synchronousSync(CuratorFramework curator, Duration timeout) {
try {
// Curator sync() is always a background operation. Use a latch to block until it finishes.
final CountDownLatch latch = new CountDownLatch(1);
curator.sync().inBackground(new BackgroundCallback() {
@Override
public void processResult(CuratorFramework curator, CuratorEvent event) throws Exception {
if (event.getType() == CuratorEventType.SYNC) {
latch.countDown();
}
}
}).forPath(curator.getNamespace().isEmpty() ? "/" : "");
// Wait for sync to complete.
return latch.await(timeout.toMillis(), TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
return false;
} catch (Exception e) {
throw Throwables.propagate(e);
}
} | java | public static boolean synchronousSync(CuratorFramework curator, Duration timeout) {
try {
// Curator sync() is always a background operation. Use a latch to block until it finishes.
final CountDownLatch latch = new CountDownLatch(1);
curator.sync().inBackground(new BackgroundCallback() {
@Override
public void processResult(CuratorFramework curator, CuratorEvent event) throws Exception {
if (event.getType() == CuratorEventType.SYNC) {
latch.countDown();
}
}
}).forPath(curator.getNamespace().isEmpty() ? "/" : "");
// Wait for sync to complete.
return latch.await(timeout.toMillis(), TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
return false;
} catch (Exception e) {
throw Throwables.propagate(e);
}
} | [
"public",
"static",
"boolean",
"synchronousSync",
"(",
"CuratorFramework",
"curator",
",",
"Duration",
"timeout",
")",
"{",
"try",
"{",
"// Curator sync() is always a background operation. Use a latch to block until it finishes.",
"final",
"CountDownLatch",
"latch",
"=",
"new"... | Performs a blocking sync operation. Returns true if the sync completed normally, false if it timed out or
was interrupted. | [
"Performs",
"a",
"blocking",
"sync",
"operation",
".",
"Returns",
"true",
"if",
"the",
"sync",
"completed",
"normally",
"false",
"if",
"it",
"timed",
"out",
"or",
"was",
"interrupted",
"."
] | 97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb | https://github.com/bazaarvoice/emodb/blob/97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb/common/zookeeper/src/main/java/com/bazaarvoice/emodb/common/zookeeper/Sync.java#L18-L38 | train |
bazaarvoice/emodb | auth/auth-core/src/main/java/com/bazaarvoice/emodb/auth/permissions/MatchingPermission.java | MatchingPermission.initializePermission | protected void initializePermission() {
try {
List<MatchingPart> parts = Lists.newArrayList();
for (String partString : split(_permission)) {
partString = partString.trim();
checkArgument(!"".equals(partString), "Permission cannot contain empty parts");
MatchingPart part = toPart(Collections.unmodifiableList(parts), partString);
parts.add(part);
}
_parts = ImmutableList.copyOf(parts);
} catch (InvalidPermissionStringException e) {
throw e;
} catch (Exception e) {
// Rethrow any uncaught exception as being caused by an invalid permission string
throw new InvalidPermissionStringException(e.getMessage(), _permission);
}
} | java | protected void initializePermission() {
try {
List<MatchingPart> parts = Lists.newArrayList();
for (String partString : split(_permission)) {
partString = partString.trim();
checkArgument(!"".equals(partString), "Permission cannot contain empty parts");
MatchingPart part = toPart(Collections.unmodifiableList(parts), partString);
parts.add(part);
}
_parts = ImmutableList.copyOf(parts);
} catch (InvalidPermissionStringException e) {
throw e;
} catch (Exception e) {
// Rethrow any uncaught exception as being caused by an invalid permission string
throw new InvalidPermissionStringException(e.getMessage(), _permission);
}
} | [
"protected",
"void",
"initializePermission",
"(",
")",
"{",
"try",
"{",
"List",
"<",
"MatchingPart",
">",
"parts",
"=",
"Lists",
".",
"newArrayList",
"(",
")",
";",
"for",
"(",
"String",
"partString",
":",
"split",
"(",
"_permission",
")",
")",
"{",
"par... | Parses and initializes the permission's parts. By default this is performed by the constructor. If a subclass
needs to perform its own initialization prior to initializing the permissions then it should call the constructor
with the initialization parameter set to false and then call this method when ready. | [
"Parses",
"and",
"initializes",
"the",
"permission",
"s",
"parts",
".",
"By",
"default",
"this",
"is",
"performed",
"by",
"the",
"constructor",
".",
"If",
"a",
"subclass",
"needs",
"to",
"perform",
"its",
"own",
"initialization",
"prior",
"to",
"initializing",... | 97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb | https://github.com/bazaarvoice/emodb/blob/97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb/auth/auth-core/src/main/java/com/bazaarvoice/emodb/auth/permissions/MatchingPermission.java#L63-L82 | train |
bazaarvoice/emodb | sor/src/main/java/com/bazaarvoice/emodb/sor/db/astyanax/DefaultChangeEncoder.java | DefaultChangeEncoder.getSeparatorIndex | private int getSeparatorIndex(ByteBuffer buf) {
int colon = BufferUtils.indexOf(buf, (byte) ':');
if (colon == -1) {
throw new IllegalStateException("Unknown encoding format: " + ByteBufferUtil.bytesToHex(buf));
}
return colon;
} | java | private int getSeparatorIndex(ByteBuffer buf) {
int colon = BufferUtils.indexOf(buf, (byte) ':');
if (colon == -1) {
throw new IllegalStateException("Unknown encoding format: " + ByteBufferUtil.bytesToHex(buf));
}
return colon;
} | [
"private",
"int",
"getSeparatorIndex",
"(",
"ByteBuffer",
"buf",
")",
"{",
"int",
"colon",
"=",
"BufferUtils",
".",
"indexOf",
"(",
"buf",
",",
"(",
"byte",
")",
"'",
"'",
")",
";",
"if",
"(",
"colon",
"==",
"-",
"1",
")",
"{",
"throw",
"new",
"Ill... | Returns the index of the colon that separates the encoding prefix from the body suffix. | [
"Returns",
"the",
"index",
"of",
"the",
"colon",
"that",
"separates",
"the",
"encoding",
"prefix",
"from",
"the",
"body",
"suffix",
"."
] | 97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb | https://github.com/bazaarvoice/emodb/blob/97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb/sor/src/main/java/com/bazaarvoice/emodb/sor/db/astyanax/DefaultChangeEncoder.java#L177-L183 | train |
bazaarvoice/emodb | sor/src/main/java/com/bazaarvoice/emodb/sor/db/ScanRange.java | ScanRange.unwrapped | public List<ScanRange> unwrapped() {
if (compare(_from, _to) < 0) {
return ImmutableList.of(this);
}
ImmutableList.Builder<ScanRange> ranges = ImmutableList.builder();
if (compare(_from, MAX_VALUE) < 0) {
ranges.add(new ScanRange(_from, MAX_VALUE));
}
if (compare(_to, MIN_VALUE) > 0) {
ranges.add(new ScanRange(MIN_VALUE, _to));
}
return ranges.build();
} | java | public List<ScanRange> unwrapped() {
if (compare(_from, _to) < 0) {
return ImmutableList.of(this);
}
ImmutableList.Builder<ScanRange> ranges = ImmutableList.builder();
if (compare(_from, MAX_VALUE) < 0) {
ranges.add(new ScanRange(_from, MAX_VALUE));
}
if (compare(_to, MIN_VALUE) > 0) {
ranges.add(new ScanRange(MIN_VALUE, _to));
}
return ranges.build();
} | [
"public",
"List",
"<",
"ScanRange",
">",
"unwrapped",
"(",
")",
"{",
"if",
"(",
"compare",
"(",
"_from",
",",
"_to",
")",
"<",
"0",
")",
"{",
"return",
"ImmutableList",
".",
"of",
"(",
"this",
")",
";",
"}",
"ImmutableList",
".",
"Builder",
"<",
"S... | If necessary splits the scan range into two range such that "from" is less than "to" in each range.
This is necessary if the scan range wraps the token range. | [
"If",
"necessary",
"splits",
"the",
"scan",
"range",
"into",
"two",
"range",
"such",
"that",
"from",
"is",
"less",
"than",
"to",
"in",
"each",
"range",
".",
"This",
"is",
"necessary",
"if",
"the",
"scan",
"range",
"wraps",
"the",
"token",
"range",
"."
] | 97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb | https://github.com/bazaarvoice/emodb/blob/97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb/sor/src/main/java/com/bazaarvoice/emodb/sor/db/ScanRange.java#L88-L100 | train |
bazaarvoice/emodb | web/src/main/java/com/bazaarvoice/emodb/web/report/ReportHistogram.java | ReportHistogram.clear | public void clear() {
_sample.clear();
_count = 0;
_max = null;
_min = null;
_sum = BigDecimal.ZERO;
_m = -1;
_s = 0;
} | java | public void clear() {
_sample.clear();
_count = 0;
_max = null;
_min = null;
_sum = BigDecimal.ZERO;
_m = -1;
_s = 0;
} | [
"public",
"void",
"clear",
"(",
")",
"{",
"_sample",
".",
"clear",
"(",
")",
";",
"_count",
"=",
"0",
";",
"_max",
"=",
"null",
";",
"_min",
"=",
"null",
";",
"_sum",
"=",
"BigDecimal",
".",
"ZERO",
";",
"_m",
"=",
"-",
"1",
";",
"_s",
"=",
"... | Clears all recorded values. | [
"Clears",
"all",
"recorded",
"values",
"."
] | 97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb | https://github.com/bazaarvoice/emodb/blob/97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb/web/src/main/java/com/bazaarvoice/emodb/web/report/ReportHistogram.java#L65-L73 | train |
bazaarvoice/emodb | sor/src/main/java/com/bazaarvoice/emodb/sor/db/astyanax/AstyanaxBlockedDataReaderDAO.java | AstyanaxBlockedDataReaderDAO.resplitLocally | @VisibleForTesting
public List<Token> resplitLocally(String startToken, String endToken, int numResplits) {
List<Token> splitTokens = ImmutableList.of(_tokenFactory.fromString(startToken), _tokenFactory.fromString(endToken));
for (int i = 0; i < numResplits; i++) {
List<Token> newTokens = new ArrayList<>(splitTokens.size() * 2 - 1);
for (int j = 0; j < splitTokens.size() - 1; j++) {
newTokens.add(splitTokens.get(j));
newTokens.add(ByteOrderedPartitioner.instance.midpoint(splitTokens.get(j), splitTokens.get(j + 1)));
}
newTokens.add(splitTokens.get(splitTokens.size() - 1));
splitTokens = newTokens;
}
return splitTokens;
} | java | @VisibleForTesting
public List<Token> resplitLocally(String startToken, String endToken, int numResplits) {
List<Token> splitTokens = ImmutableList.of(_tokenFactory.fromString(startToken), _tokenFactory.fromString(endToken));
for (int i = 0; i < numResplits; i++) {
List<Token> newTokens = new ArrayList<>(splitTokens.size() * 2 - 1);
for (int j = 0; j < splitTokens.size() - 1; j++) {
newTokens.add(splitTokens.get(j));
newTokens.add(ByteOrderedPartitioner.instance.midpoint(splitTokens.get(j), splitTokens.get(j + 1)));
}
newTokens.add(splitTokens.get(splitTokens.size() - 1));
splitTokens = newTokens;
}
return splitTokens;
} | [
"@",
"VisibleForTesting",
"public",
"List",
"<",
"Token",
">",
"resplitLocally",
"(",
"String",
"startToken",
",",
"String",
"endToken",
",",
"int",
"numResplits",
")",
"{",
"List",
"<",
"Token",
">",
"splitTokens",
"=",
"ImmutableList",
".",
"of",
"(",
"_to... | Manually split the token ranges using ByteOrderedPartitioner's midpoint method | [
"Manually",
"split",
"the",
"token",
"ranges",
"using",
"ByteOrderedPartitioner",
"s",
"midpoint",
"method"
] | 97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb | https://github.com/bazaarvoice/emodb/blob/97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb/sor/src/main/java/com/bazaarvoice/emodb/sor/db/astyanax/AstyanaxBlockedDataReaderDAO.java#L387-L400 | train |
bazaarvoice/emodb | sor/src/main/java/com/bazaarvoice/emodb/sor/db/astyanax/AstyanaxBlockedDataReaderDAO.java | AstyanaxBlockedDataReaderDAO.rowQuery | private Iterator<Record> rowQuery(DeltaPlacement placement,
List<Map.Entry<ByteBuffer, Key>> keys,
ReadConsistency consistency) {
// Build the list of row IDs to query for.
List<ByteBuffer> rowIds = Lists.transform(keys, entryKeyFunction());
// Query for Delta & Compaction info, just the first 50 columns for now.
final Rows<ByteBuffer, DeltaKey> rows = execute(placement.getKeyspace()
.prepareQuery(placement.getBlockedDeltaColumnFamily(), SorConsistencies.toAstyanax(consistency))
.getKeySlice(rowIds)
.withColumnRange(_maxColumnsRange),
"query %d keys from placement %s", rowIds.size(), placement.getName());
// Track metrics
_randomReadMeter.mark(rowIds.size());
// Return an iterator that decodes the row results, avoiding pinning multiple decoded rows into memory at once.
return decodeRows(keys, rows, _maxColumnsRange.getLimit(), consistency);
} | java | private Iterator<Record> rowQuery(DeltaPlacement placement,
List<Map.Entry<ByteBuffer, Key>> keys,
ReadConsistency consistency) {
// Build the list of row IDs to query for.
List<ByteBuffer> rowIds = Lists.transform(keys, entryKeyFunction());
// Query for Delta & Compaction info, just the first 50 columns for now.
final Rows<ByteBuffer, DeltaKey> rows = execute(placement.getKeyspace()
.prepareQuery(placement.getBlockedDeltaColumnFamily(), SorConsistencies.toAstyanax(consistency))
.getKeySlice(rowIds)
.withColumnRange(_maxColumnsRange),
"query %d keys from placement %s", rowIds.size(), placement.getName());
// Track metrics
_randomReadMeter.mark(rowIds.size());
// Return an iterator that decodes the row results, avoiding pinning multiple decoded rows into memory at once.
return decodeRows(keys, rows, _maxColumnsRange.getLimit(), consistency);
} | [
"private",
"Iterator",
"<",
"Record",
">",
"rowQuery",
"(",
"DeltaPlacement",
"placement",
",",
"List",
"<",
"Map",
".",
"Entry",
"<",
"ByteBuffer",
",",
"Key",
">",
">",
"keys",
",",
"ReadConsistency",
"consistency",
")",
"{",
"// Build the list of row IDs to q... | Queries for rows given an enumerated list of Cassandra row keys. | [
"Queries",
"for",
"rows",
"given",
"an",
"enumerated",
"list",
"of",
"Cassandra",
"row",
"keys",
"."
] | 97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb | https://github.com/bazaarvoice/emodb/blob/97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb/sor/src/main/java/com/bazaarvoice/emodb/sor/db/astyanax/AstyanaxBlockedDataReaderDAO.java#L786-L804 | train |
bazaarvoice/emodb | sor/src/main/java/com/bazaarvoice/emodb/sor/db/astyanax/AstyanaxBlockedDataReaderDAO.java | AstyanaxBlockedDataReaderDAO.decodeKeys | private Iterator<String> decodeKeys(final Iterator<Row<ByteBuffer, DeltaKey>> iter) {
return new AbstractIterator<String>() {
@Override
protected String computeNext() {
while (iter.hasNext()) {
Row<ByteBuffer, DeltaKey> row = iter.next();
if (!row.getColumns().isEmpty()) { // Ignore range ghosts
return AstyanaxStorage.getContentKey(row.getRawKey());
}
}
return endOfData();
}
};
} | java | private Iterator<String> decodeKeys(final Iterator<Row<ByteBuffer, DeltaKey>> iter) {
return new AbstractIterator<String>() {
@Override
protected String computeNext() {
while (iter.hasNext()) {
Row<ByteBuffer, DeltaKey> row = iter.next();
if (!row.getColumns().isEmpty()) { // Ignore range ghosts
return AstyanaxStorage.getContentKey(row.getRawKey());
}
}
return endOfData();
}
};
} | [
"private",
"Iterator",
"<",
"String",
">",
"decodeKeys",
"(",
"final",
"Iterator",
"<",
"Row",
"<",
"ByteBuffer",
",",
"DeltaKey",
">",
">",
"iter",
")",
"{",
"return",
"new",
"AbstractIterator",
"<",
"String",
">",
"(",
")",
"{",
"@",
"Override",
"prote... | Decodes row keys returned by scanning a table. | [
"Decodes",
"row",
"keys",
"returned",
"by",
"scanning",
"a",
"table",
"."
] | 97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb | https://github.com/bazaarvoice/emodb/blob/97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb/sor/src/main/java/com/bazaarvoice/emodb/sor/db/astyanax/AstyanaxBlockedDataReaderDAO.java#L1035-L1048 | train |
bazaarvoice/emodb | sor/src/main/java/com/bazaarvoice/emodb/sor/db/astyanax/AstyanaxBlockedDataReaderDAO.java | AstyanaxBlockedDataReaderDAO.decodeRows | private Iterator<Record> decodeRows(List<Map.Entry<ByteBuffer, Key>> keys, final Rows<ByteBuffer, DeltaKey> rows,
final int largeRowThreshold, final ReadConsistency consistency) {
// Avoiding pinning multiple decoded rows into memory at once.
return Iterators.transform(keys.iterator(), new Function<Map.Entry<ByteBuffer, Key>, Record>() {
@Override
public Record apply(Map.Entry<ByteBuffer, Key> entry) {
Row<ByteBuffer, DeltaKey> row = rows.getRow(entry.getKey());
if (row == null) {
return emptyRecord(entry.getValue());
}
// Convert the results into a Record object, lazily fetching the rest of the columns as necessary.
return newRecord(entry.getValue(), row.getRawKey(), row.getColumns(), largeRowThreshold, consistency, null);
}
});
} | java | private Iterator<Record> decodeRows(List<Map.Entry<ByteBuffer, Key>> keys, final Rows<ByteBuffer, DeltaKey> rows,
final int largeRowThreshold, final ReadConsistency consistency) {
// Avoiding pinning multiple decoded rows into memory at once.
return Iterators.transform(keys.iterator(), new Function<Map.Entry<ByteBuffer, Key>, Record>() {
@Override
public Record apply(Map.Entry<ByteBuffer, Key> entry) {
Row<ByteBuffer, DeltaKey> row = rows.getRow(entry.getKey());
if (row == null) {
return emptyRecord(entry.getValue());
}
// Convert the results into a Record object, lazily fetching the rest of the columns as necessary.
return newRecord(entry.getValue(), row.getRawKey(), row.getColumns(), largeRowThreshold, consistency, null);
}
});
} | [
"private",
"Iterator",
"<",
"Record",
">",
"decodeRows",
"(",
"List",
"<",
"Map",
".",
"Entry",
"<",
"ByteBuffer",
",",
"Key",
">",
">",
"keys",
",",
"final",
"Rows",
"<",
"ByteBuffer",
",",
"DeltaKey",
">",
"rows",
",",
"final",
"int",
"largeRowThreshol... | Decodes rows returned by querying for a specific set of rows. | [
"Decodes",
"rows",
"returned",
"by",
"querying",
"for",
"a",
"specific",
"set",
"of",
"rows",
"."
] | 97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb | https://github.com/bazaarvoice/emodb/blob/97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb/sor/src/main/java/com/bazaarvoice/emodb/sor/db/astyanax/AstyanaxBlockedDataReaderDAO.java#L1053-L1067 | train |
bazaarvoice/emodb | sor/src/main/java/com/bazaarvoice/emodb/sor/db/astyanax/AstyanaxBlockedDataReaderDAO.java | AstyanaxBlockedDataReaderDAO.touch | private <T> Iterator<T> touch(Iterator<T> iter) {
// Could return a Guava PeekingIterator after "if (iter.hasNext()) iter.peek()", but simply calling hasNext()
// is sufficient for the iterator implementations used by this DAO class...
iter.hasNext();
return iter;
} | java | private <T> Iterator<T> touch(Iterator<T> iter) {
// Could return a Guava PeekingIterator after "if (iter.hasNext()) iter.peek()", but simply calling hasNext()
// is sufficient for the iterator implementations used by this DAO class...
iter.hasNext();
return iter;
} | [
"private",
"<",
"T",
">",
"Iterator",
"<",
"T",
">",
"touch",
"(",
"Iterator",
"<",
"T",
">",
"iter",
")",
"{",
"// Could return a Guava PeekingIterator after \"if (iter.hasNext()) iter.peek()\", but simply calling hasNext()",
"// is sufficient for the iterator implementations us... | Force computation of the first item in an iterator so metrics calculations for a method reflect the cost of
the first batch of results. | [
"Force",
"computation",
"of",
"the",
"first",
"item",
"in",
"an",
"iterator",
"so",
"metrics",
"calculations",
"for",
"a",
"method",
"reflect",
"the",
"cost",
"of",
"the",
"first",
"batch",
"of",
"results",
"."
] | 97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb | https://github.com/bazaarvoice/emodb/blob/97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb/sor/src/main/java/com/bazaarvoice/emodb/sor/db/astyanax/AstyanaxBlockedDataReaderDAO.java#L1295-L1300 | train |
bazaarvoice/emodb | common/astyanax/src/main/java/com/bazaarvoice/emodb/common/cassandra/ConsistencyTopologyAdapter.java | ConsistencyTopologyAdapter.clamp | public ConsistencyLevel clamp(ConsistencyLevel consistencyLevel) {
// Cassandra only allows the use of LOCAL_QUORUM and EACH_QUORUM if the keyspace
// placement strategy is NetworkTopologyStrategy
if ((consistencyLevel == ConsistencyLevel.CL_LOCAL_QUORUM || consistencyLevel == ConsistencyLevel.CL_EACH_QUORUM) && !_networkTopology) {
consistencyLevel = ConsistencyLevel.CL_QUORUM;
}
if (consistencyLevel == ConsistencyLevel.CL_LOCAL_ONE && !_networkTopology) {
consistencyLevel = ConsistencyLevel.CL_ONE;
}
// we may want to write to at two or three servers to ensure the write survives the
// permanent failure of any single server. but if the ring has fewer servers to
// begin with (ie. it's a test ring) we must reduce the consistency level.
if (consistencyLevel == ConsistencyLevel.CL_THREE && _replicationFactor < 3) {
consistencyLevel = ConsistencyLevel.CL_TWO;
}
if (consistencyLevel == ConsistencyLevel.CL_TWO && _replicationFactor < 2) {
consistencyLevel = ConsistencyLevel.CL_ONE;
}
return consistencyLevel;
} | java | public ConsistencyLevel clamp(ConsistencyLevel consistencyLevel) {
// Cassandra only allows the use of LOCAL_QUORUM and EACH_QUORUM if the keyspace
// placement strategy is NetworkTopologyStrategy
if ((consistencyLevel == ConsistencyLevel.CL_LOCAL_QUORUM || consistencyLevel == ConsistencyLevel.CL_EACH_QUORUM) && !_networkTopology) {
consistencyLevel = ConsistencyLevel.CL_QUORUM;
}
if (consistencyLevel == ConsistencyLevel.CL_LOCAL_ONE && !_networkTopology) {
consistencyLevel = ConsistencyLevel.CL_ONE;
}
// we may want to write to at two or three servers to ensure the write survives the
// permanent failure of any single server. but if the ring has fewer servers to
// begin with (ie. it's a test ring) we must reduce the consistency level.
if (consistencyLevel == ConsistencyLevel.CL_THREE && _replicationFactor < 3) {
consistencyLevel = ConsistencyLevel.CL_TWO;
}
if (consistencyLevel == ConsistencyLevel.CL_TWO && _replicationFactor < 2) {
consistencyLevel = ConsistencyLevel.CL_ONE;
}
return consistencyLevel;
} | [
"public",
"ConsistencyLevel",
"clamp",
"(",
"ConsistencyLevel",
"consistencyLevel",
")",
"{",
"// Cassandra only allows the use of LOCAL_QUORUM and EACH_QUORUM if the keyspace",
"// placement strategy is NetworkTopologyStrategy",
"if",
"(",
"(",
"consistencyLevel",
"==",
"ConsistencyLe... | Reduce the desired consistency level to be compatible with the deployed ring topology. | [
"Reduce",
"the",
"desired",
"consistency",
"level",
"to",
"be",
"compatible",
"with",
"the",
"deployed",
"ring",
"topology",
"."
] | 97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb | https://github.com/bazaarvoice/emodb/blob/97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb/common/astyanax/src/main/java/com/bazaarvoice/emodb/common/cassandra/ConsistencyTopologyAdapter.java#L18-L39 | train |
bazaarvoice/emodb | sor/src/main/java/com/bazaarvoice/emodb/sor/db/astyanax/StitchedColumn.java | StitchedColumn.getValue | @Override
public <V> V getValue(Serializer<V> serializer) {
return _content != null ? serializer.fromByteBuffer(_content) : _oldColumn.getValue(serializer);
} | java | @Override
public <V> V getValue(Serializer<V> serializer) {
return _content != null ? serializer.fromByteBuffer(_content) : _oldColumn.getValue(serializer);
} | [
"@",
"Override",
"public",
"<",
"V",
">",
"V",
"getValue",
"(",
"Serializer",
"<",
"V",
">",
"serializer",
")",
"{",
"return",
"_content",
"!=",
"null",
"?",
"serializer",
".",
"fromByteBuffer",
"(",
"_content",
")",
":",
"_oldColumn",
".",
"getValue",
"... | content will be null if delta fit in a single block, as no stitching was performed | [
"content",
"will",
"be",
"null",
"if",
"delta",
"fit",
"in",
"a",
"single",
"block",
"as",
"no",
"stitching",
"was",
"performed"
] | 97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb | https://github.com/bazaarvoice/emodb/blob/97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb/sor/src/main/java/com/bazaarvoice/emodb/sor/db/astyanax/StitchedColumn.java#L41-L44 | train |
bazaarvoice/emodb | web-local/src/main/java/com/bazaarvoice/emodb/local/EmoServiceWithZK.java | EmoServiceWithZK.startLocalCassandra | private static void startLocalCassandra(String cassandraYamlPath) throws IOException {
System.setProperty("cassandra.config", "file:" + cassandraYamlPath);
final CassandraDaemon cassandra = new CassandraDaemon();
cassandra.init(null);
Futures.getUnchecked(service.submit(new Callable<Object>(){
@Override
public Object call() throws Exception
{
cassandra.start();
return null;
}
}));
} | java | private static void startLocalCassandra(String cassandraYamlPath) throws IOException {
System.setProperty("cassandra.config", "file:" + cassandraYamlPath);
final CassandraDaemon cassandra = new CassandraDaemon();
cassandra.init(null);
Futures.getUnchecked(service.submit(new Callable<Object>(){
@Override
public Object call() throws Exception
{
cassandra.start();
return null;
}
}));
} | [
"private",
"static",
"void",
"startLocalCassandra",
"(",
"String",
"cassandraYamlPath",
")",
"throws",
"IOException",
"{",
"System",
".",
"setProperty",
"(",
"\"cassandra.config\"",
",",
"\"file:\"",
"+",
"cassandraYamlPath",
")",
";",
"final",
"CassandraDaemon",
"cas... | Start an in-memory Cassandra. | [
"Start",
"an",
"in",
"-",
"memory",
"Cassandra",
"."
] | 97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb | https://github.com/bazaarvoice/emodb/blob/97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb/web-local/src/main/java/com/bazaarvoice/emodb/local/EmoServiceWithZK.java#L148-L161 | train |
bazaarvoice/emodb | web-local/src/main/java/com/bazaarvoice/emodb/local/EmoServiceWithZK.java | EmoServiceWithZK.startLocalZooKeeper | private static TestingServer startLocalZooKeeper() throws Exception {
// ZooKeeper is too noisy by default.
((Logger) LoggerFactory.getLogger("org.apache.zookeeper")).setLevel(Level.ERROR);
// Start the testing server.
TestingServer zooKeeperServer = new TestingServer(2181);
// Configure EmoDB to use the testing server.
System.setProperty("dw.zooKeeper.connectString", zooKeeperServer.getConnectString());
return zooKeeperServer;
} | java | private static TestingServer startLocalZooKeeper() throws Exception {
// ZooKeeper is too noisy by default.
((Logger) LoggerFactory.getLogger("org.apache.zookeeper")).setLevel(Level.ERROR);
// Start the testing server.
TestingServer zooKeeperServer = new TestingServer(2181);
// Configure EmoDB to use the testing server.
System.setProperty("dw.zooKeeper.connectString", zooKeeperServer.getConnectString());
return zooKeeperServer;
} | [
"private",
"static",
"TestingServer",
"startLocalZooKeeper",
"(",
")",
"throws",
"Exception",
"{",
"// ZooKeeper is too noisy by default.",
"(",
"(",
"Logger",
")",
"LoggerFactory",
".",
"getLogger",
"(",
"\"org.apache.zookeeper\"",
")",
")",
".",
"setLevel",
"(",
"Le... | Start an in-memory copy of ZooKeeper. | [
"Start",
"an",
"in",
"-",
"memory",
"copy",
"of",
"ZooKeeper",
"."
] | 97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb | https://github.com/bazaarvoice/emodb/blob/97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb/web-local/src/main/java/com/bazaarvoice/emodb/local/EmoServiceWithZK.java#L164-L175 | train |
bazaarvoice/emodb | web/src/main/java/com/bazaarvoice/emodb/web/migrator/DeltaMigrator.java | DeltaMigrator.resubmitWorkflowTasks | public MigratorStatus resubmitWorkflowTasks(String placement) {
MigratorStatus status = _statusDAO.getMigratorStatus(placement);
if (status == null) {
return null;
}
if (status.getCompleteTime() == null) {
// Resubmit any active tasks
for (ScanRangeStatus active : status.getActiveScanRanges()) {
_workflow.addScanRangeTask(placement, active.getTaskId(), active.getPlacement(), active.getScanRange());
}
// Send notification to evaluate whether any new range tasks can be started
_workflow.scanStatusUpdated(placement);
}
return status;
} | java | public MigratorStatus resubmitWorkflowTasks(String placement) {
MigratorStatus status = _statusDAO.getMigratorStatus(placement);
if (status == null) {
return null;
}
if (status.getCompleteTime() == null) {
// Resubmit any active tasks
for (ScanRangeStatus active : status.getActiveScanRanges()) {
_workflow.addScanRangeTask(placement, active.getTaskId(), active.getPlacement(), active.getScanRange());
}
// Send notification to evaluate whether any new range tasks can be started
_workflow.scanStatusUpdated(placement);
}
return status;
} | [
"public",
"MigratorStatus",
"resubmitWorkflowTasks",
"(",
"String",
"placement",
")",
"{",
"MigratorStatus",
"status",
"=",
"_statusDAO",
".",
"getMigratorStatus",
"(",
"placement",
")",
";",
"if",
"(",
"status",
"==",
"null",
")",
"{",
"return",
"null",
";",
... | Sometimes due to unexpected errors while submitting migrator ranges to the underlying queues a migration can get stuck.
This method takes all available tasks for a migration and resubmits them. This method is safe because
the underlying system is resilient to task resubmissions and concurrent work on the same task. | [
"Sometimes",
"due",
"to",
"unexpected",
"errors",
"while",
"submitting",
"migrator",
"ranges",
"to",
"the",
"underlying",
"queues",
"a",
"migration",
"can",
"get",
"stuck",
".",
"This",
"method",
"takes",
"all",
"available",
"tasks",
"for",
"a",
"migration",
"... | 97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb | https://github.com/bazaarvoice/emodb/blob/97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb/web/src/main/java/com/bazaarvoice/emodb/web/migrator/DeltaMigrator.java#L129-L146 | train |
bazaarvoice/emodb | sor/src/main/java/com/bazaarvoice/emodb/sor/db/astyanax/CqlDataReaderDAO.java | CqlDataReaderDAO.read | @Override
public Record read(Key key, ReadConsistency consistency) {
checkNotNull(key, "key");
checkNotNull(consistency, "consistency");
AstyanaxTable table = (AstyanaxTable) key.getTable();
AstyanaxStorage storage = table.getReadStorage();
DeltaPlacement placement = (DeltaPlacement) storage.getPlacement();
ByteBuffer rowKey = storage.getRowKey(key.getKey());
return read(key, rowKey, consistency, placement);
} | java | @Override
public Record read(Key key, ReadConsistency consistency) {
checkNotNull(key, "key");
checkNotNull(consistency, "consistency");
AstyanaxTable table = (AstyanaxTable) key.getTable();
AstyanaxStorage storage = table.getReadStorage();
DeltaPlacement placement = (DeltaPlacement) storage.getPlacement();
ByteBuffer rowKey = storage.getRowKey(key.getKey());
return read(key, rowKey, consistency, placement);
} | [
"@",
"Override",
"public",
"Record",
"read",
"(",
"Key",
"key",
",",
"ReadConsistency",
"consistency",
")",
"{",
"checkNotNull",
"(",
"key",
",",
"\"key\"",
")",
";",
"checkNotNull",
"(",
"consistency",
",",
"\"consistency\"",
")",
";",
"AstyanaxTable",
"table... | This CQL based read method works for a row with 64 deltas of 3 MB each. The same read with the AstyanaxDataReaderDAO
would give Thrift frame errors. | [
"This",
"CQL",
"based",
"read",
"method",
"works",
"for",
"a",
"row",
"with",
"64",
"deltas",
"of",
"3",
"MB",
"each",
".",
"The",
"same",
"read",
"with",
"the",
"AstyanaxDataReaderDAO",
"would",
"give",
"Thrift",
"frame",
"errors",
"."
] | 97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb | https://github.com/bazaarvoice/emodb/blob/97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb/sor/src/main/java/com/bazaarvoice/emodb/sor/db/astyanax/CqlDataReaderDAO.java#L158-L169 | train |
bazaarvoice/emodb | sor/src/main/java/com/bazaarvoice/emodb/sor/db/astyanax/CqlDataReaderDAO.java | CqlDataReaderDAO.getSplits | @Override
public List<String> getSplits(Table table, int recordsPerSplit, int localResplits) throws TimeoutException {
return _astyanaxReaderDAO.getSplits(table, recordsPerSplit, localResplits);
} | java | @Override
public List<String> getSplits(Table table, int recordsPerSplit, int localResplits) throws TimeoutException {
return _astyanaxReaderDAO.getSplits(table, recordsPerSplit, localResplits);
} | [
"@",
"Override",
"public",
"List",
"<",
"String",
">",
"getSplits",
"(",
"Table",
"table",
",",
"int",
"recordsPerSplit",
",",
"int",
"localResplits",
")",
"throws",
"TimeoutException",
"{",
"return",
"_astyanaxReaderDAO",
".",
"getSplits",
"(",
"table",
",",
... | support for this call using CQL. Therefore they must always defer to the Asytanax implementation. | [
"support",
"for",
"this",
"call",
"using",
"CQL",
".",
"Therefore",
"they",
"must",
"always",
"defer",
"to",
"the",
"Asytanax",
"implementation",
"."
] | 97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb | https://github.com/bazaarvoice/emodb/blob/97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb/sor/src/main/java/com/bazaarvoice/emodb/sor/db/astyanax/CqlDataReaderDAO.java#L925-L928 | train |
bazaarvoice/emodb | web/src/main/java/com/bazaarvoice/emodb/web/scanner/control/LocalScanUploadMonitor.java | LocalScanUploadMonitor.resplitPartiallyCompleteTasks | private ScanStatus resplitPartiallyCompleteTasks(ScanStatus status) {
boolean anyUpdated = false;
int nextTaskId = -1;
for (ScanRangeStatus complete : status.getCompleteScanRanges()) {
if (complete.getResplitRange().isPresent()) {
// This task only partially completed; there are still more data to scan.
if (nextTaskId == -1) {
nextTaskId = getNextTaskId(status);
}
ScanRange resplitRange = complete.getResplitRange().get();
// Resplit the un-scanned portion into new ranges
List<ScanRange> subRanges = resplit(complete.getPlacement(), resplitRange, status.getOptions().getRangeScanSplitSize());
// Create new tasks for each subrange that are immediately available for being queued.
List<ScanRangeStatus> resplitStatuses = Lists.newArrayListWithCapacity(subRanges.size());
for (ScanRange subRange : subRanges) {
resplitStatuses.add(
new ScanRangeStatus(nextTaskId++, complete.getPlacement(), subRange,
complete.getBatchId(), complete.getBlockedByBatchId(), complete.getConcurrencyId()));
}
_scanStatusDAO.resplitScanRangeTask(status.getScanId(), complete.getTaskId(), resplitStatuses);
anyUpdated = true;
}
}
if (!anyUpdated) {
return status;
}
// Slightly inefficient to reload but less risky than trying to keep the DAO and in-memory object in sync
return _scanStatusDAO.getScanStatus(status.getScanId());
} | java | private ScanStatus resplitPartiallyCompleteTasks(ScanStatus status) {
boolean anyUpdated = false;
int nextTaskId = -1;
for (ScanRangeStatus complete : status.getCompleteScanRanges()) {
if (complete.getResplitRange().isPresent()) {
// This task only partially completed; there are still more data to scan.
if (nextTaskId == -1) {
nextTaskId = getNextTaskId(status);
}
ScanRange resplitRange = complete.getResplitRange().get();
// Resplit the un-scanned portion into new ranges
List<ScanRange> subRanges = resplit(complete.getPlacement(), resplitRange, status.getOptions().getRangeScanSplitSize());
// Create new tasks for each subrange that are immediately available for being queued.
List<ScanRangeStatus> resplitStatuses = Lists.newArrayListWithCapacity(subRanges.size());
for (ScanRange subRange : subRanges) {
resplitStatuses.add(
new ScanRangeStatus(nextTaskId++, complete.getPlacement(), subRange,
complete.getBatchId(), complete.getBlockedByBatchId(), complete.getConcurrencyId()));
}
_scanStatusDAO.resplitScanRangeTask(status.getScanId(), complete.getTaskId(), resplitStatuses);
anyUpdated = true;
}
}
if (!anyUpdated) {
return status;
}
// Slightly inefficient to reload but less risky than trying to keep the DAO and in-memory object in sync
return _scanStatusDAO.getScanStatus(status.getScanId());
} | [
"private",
"ScanStatus",
"resplitPartiallyCompleteTasks",
"(",
"ScanStatus",
"status",
")",
"{",
"boolean",
"anyUpdated",
"=",
"false",
";",
"int",
"nextTaskId",
"=",
"-",
"1",
";",
"for",
"(",
"ScanRangeStatus",
"complete",
":",
"status",
".",
"getCompleteScanRan... | Checks whether any completed tasks returned before scanning the entire range. If so then the unscanned
ranges are resplit and new tasks are created from them. | [
"Checks",
"whether",
"any",
"completed",
"tasks",
"returned",
"before",
"scanning",
"the",
"entire",
"range",
".",
"If",
"so",
"then",
"the",
"unscanned",
"ranges",
"are",
"resplit",
"and",
"new",
"tasks",
"are",
"created",
"from",
"them",
"."
] | 97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb | https://github.com/bazaarvoice/emodb/blob/97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb/web/src/main/java/com/bazaarvoice/emodb/web/scanner/control/LocalScanUploadMonitor.java#L282-L317 | train |
bazaarvoice/emodb | common/client/src/main/java/com/bazaarvoice/emodb/client/EntityHelper.java | EntityHelper.getEntity | public static <T> T getEntity(InputStream in, Class<T> clazz) {
if (clazz == InputStream.class) {
//noinspection unchecked
return (T) clazz;
}
try {
return JsonHelper.readJson(in, clazz);
} catch (IOException e) {
throw Throwables.propagate(e);
}
} | java | public static <T> T getEntity(InputStream in, Class<T> clazz) {
if (clazz == InputStream.class) {
//noinspection unchecked
return (T) clazz;
}
try {
return JsonHelper.readJson(in, clazz);
} catch (IOException e) {
throw Throwables.propagate(e);
}
} | [
"public",
"static",
"<",
"T",
">",
"T",
"getEntity",
"(",
"InputStream",
"in",
",",
"Class",
"<",
"T",
">",
"clazz",
")",
"{",
"if",
"(",
"clazz",
"==",
"InputStream",
".",
"class",
")",
"{",
"//noinspection unchecked",
"return",
"(",
"T",
")",
"clazz"... | Reads the entity input stream and deserializes the JSON content to the given class. | [
"Reads",
"the",
"entity",
"input",
"stream",
"and",
"deserializes",
"the",
"JSON",
"content",
"to",
"the",
"given",
"class",
"."
] | 97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb | https://github.com/bazaarvoice/emodb/blob/97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb/common/client/src/main/java/com/bazaarvoice/emodb/client/EntityHelper.java#L23-L34 | train |
bazaarvoice/emodb | common/client/src/main/java/com/bazaarvoice/emodb/client/EntityHelper.java | EntityHelper.typeReferenceFrom | private static <T> TypeReference<T> typeReferenceFrom(final Type type) {
return new TypeReference<T>() {
@Override
public Type getType() {
return type;
}
};
} | java | private static <T> TypeReference<T> typeReferenceFrom(final Type type) {
return new TypeReference<T>() {
@Override
public Type getType() {
return type;
}
};
} | [
"private",
"static",
"<",
"T",
">",
"TypeReference",
"<",
"T",
">",
"typeReferenceFrom",
"(",
"final",
"Type",
"type",
")",
"{",
"return",
"new",
"TypeReference",
"<",
"T",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"Type",
"getType",
"(",
")",
"{"... | Internal method for creating a TypeReference from a Java Type. | [
"Internal",
"method",
"for",
"creating",
"a",
"TypeReference",
"from",
"a",
"Java",
"Type",
"."
] | 97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb | https://github.com/bazaarvoice/emodb/blob/97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb/common/client/src/main/java/com/bazaarvoice/emodb/client/EntityHelper.java#L63-L70 | train |
bazaarvoice/emodb | common/stash/src/main/java/com/bazaarvoice/emodb/common/stash/StashReader.java | StashReader.getS3Client | protected static AmazonS3 getS3Client(URI stashRoot, AWSCredentialsProvider credentialsProvider) {
return getS3Client(stashRoot, credentialsProvider, null);
} | java | protected static AmazonS3 getS3Client(URI stashRoot, AWSCredentialsProvider credentialsProvider) {
return getS3Client(stashRoot, credentialsProvider, null);
} | [
"protected",
"static",
"AmazonS3",
"getS3Client",
"(",
"URI",
"stashRoot",
",",
"AWSCredentialsProvider",
"credentialsProvider",
")",
"{",
"return",
"getS3Client",
"(",
"stashRoot",
",",
"credentialsProvider",
",",
"null",
")",
";",
"}"
] | Utility method to get the S3 client for a credentials provider. | [
"Utility",
"method",
"to",
"get",
"the",
"S3",
"client",
"for",
"a",
"credentials",
"provider",
"."
] | 97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb | https://github.com/bazaarvoice/emodb/blob/97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb/common/stash/src/main/java/com/bazaarvoice/emodb/common/stash/StashReader.java#L70-L72 | train |
bazaarvoice/emodb | common/stash/src/main/java/com/bazaarvoice/emodb/common/stash/StashReader.java | StashReader.listTables | public Iterator<StashTable> listTables() {
final String root = getRootPath();
final String prefix = String.format("%s/", root);
return new AbstractIterator<StashTable>() {
Iterator<String> _commonPrefixes = Iterators.emptyIterator();
String _marker = null;
boolean _truncated = true;
@Override
protected StashTable computeNext() {
String dir = null;
while (dir == null) {
if (_commonPrefixes.hasNext()) {
dir = _commonPrefixes.next();
if (dir.isEmpty()) {
// Ignore the empty directory if it comes back
dir = null;
} else {
// Strip the prefix and trailing "/"
dir = dir.substring(prefix.length(), dir.length()-1);
}
} else if (_truncated) {
ObjectListing response = _s3.listObjects(new ListObjectsRequest()
.withBucketName(_bucket)
.withPrefix(prefix)
.withDelimiter("/")
.withMarker(_marker)
.withMaxKeys(1000));
_commonPrefixes = response.getCommonPrefixes().iterator();
_marker = response.getNextMarker();
_truncated = response.isTruncated();
} else {
return endOfData();
}
}
String tablePrefix = prefix + dir + "/";
String tableName = StashUtil.decodeStashTable(dir);
return new StashTable(_bucket, tablePrefix, tableName);
}
};
} | java | public Iterator<StashTable> listTables() {
final String root = getRootPath();
final String prefix = String.format("%s/", root);
return new AbstractIterator<StashTable>() {
Iterator<String> _commonPrefixes = Iterators.emptyIterator();
String _marker = null;
boolean _truncated = true;
@Override
protected StashTable computeNext() {
String dir = null;
while (dir == null) {
if (_commonPrefixes.hasNext()) {
dir = _commonPrefixes.next();
if (dir.isEmpty()) {
// Ignore the empty directory if it comes back
dir = null;
} else {
// Strip the prefix and trailing "/"
dir = dir.substring(prefix.length(), dir.length()-1);
}
} else if (_truncated) {
ObjectListing response = _s3.listObjects(new ListObjectsRequest()
.withBucketName(_bucket)
.withPrefix(prefix)
.withDelimiter("/")
.withMarker(_marker)
.withMaxKeys(1000));
_commonPrefixes = response.getCommonPrefixes().iterator();
_marker = response.getNextMarker();
_truncated = response.isTruncated();
} else {
return endOfData();
}
}
String tablePrefix = prefix + dir + "/";
String tableName = StashUtil.decodeStashTable(dir);
return new StashTable(_bucket, tablePrefix, tableName);
}
};
} | [
"public",
"Iterator",
"<",
"StashTable",
">",
"listTables",
"(",
")",
"{",
"final",
"String",
"root",
"=",
"getRootPath",
"(",
")",
";",
"final",
"String",
"prefix",
"=",
"String",
".",
"format",
"(",
"\"%s/\"",
",",
"root",
")",
";",
"return",
"new",
... | Gets all tables available in this stash. | [
"Gets",
"all",
"tables",
"available",
"in",
"this",
"stash",
"."
] | 97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb | https://github.com/bazaarvoice/emodb/blob/97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb/common/stash/src/main/java/com/bazaarvoice/emodb/common/stash/StashReader.java#L154-L198 | train |
bazaarvoice/emodb | common/stash/src/main/java/com/bazaarvoice/emodb/common/stash/StashReader.java | StashReader.getSplits | public List<StashSplit> getSplits(String table)
throws StashNotAvailableException, TableNotStashedException {
ImmutableList.Builder<StashSplit> splitsBuilder = ImmutableList.builder();
Iterator<S3ObjectSummary> objectSummaries = getS3ObjectSummariesForTable(table);
while (objectSummaries.hasNext()) {
S3ObjectSummary objectSummary = objectSummaries.next();
String key = objectSummary.getKey();
// Strip the common root path prefix from the split since it is constant.
splitsBuilder.add(new StashSplit(table, key.substring(_rootPath.length() + 1), objectSummary.getSize()));
}
return splitsBuilder.build();
} | java | public List<StashSplit> getSplits(String table)
throws StashNotAvailableException, TableNotStashedException {
ImmutableList.Builder<StashSplit> splitsBuilder = ImmutableList.builder();
Iterator<S3ObjectSummary> objectSummaries = getS3ObjectSummariesForTable(table);
while (objectSummaries.hasNext()) {
S3ObjectSummary objectSummary = objectSummaries.next();
String key = objectSummary.getKey();
// Strip the common root path prefix from the split since it is constant.
splitsBuilder.add(new StashSplit(table, key.substring(_rootPath.length() + 1), objectSummary.getSize()));
}
return splitsBuilder.build();
} | [
"public",
"List",
"<",
"StashSplit",
">",
"getSplits",
"(",
"String",
"table",
")",
"throws",
"StashNotAvailableException",
",",
"TableNotStashedException",
"{",
"ImmutableList",
".",
"Builder",
"<",
"StashSplit",
">",
"splitsBuilder",
"=",
"ImmutableList",
".",
"bu... | Get the splits for a record stored in stash. Each split corresponds to a file in the Stash table's directory. | [
"Get",
"the",
"splits",
"for",
"a",
"record",
"stored",
"in",
"stash",
".",
"Each",
"split",
"corresponds",
"to",
"a",
"file",
"in",
"the",
"Stash",
"table",
"s",
"directory",
"."
] | 97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb | https://github.com/bazaarvoice/emodb/blob/97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb/common/stash/src/main/java/com/bazaarvoice/emodb/common/stash/StashReader.java#L306-L319 | train |
bazaarvoice/emodb | databus/src/main/java/com/bazaarvoice/emodb/databus/db/cql/CqlSubscriptionDAO.java | CqlSubscriptionDAO.getColumnNames | private void getColumnNames() {
TableMetadata table = _keyspace.getKeyspaceMetadata().getTable(CF_NAME);
_rowkeyColumn = table.getPrimaryKey().get(0).getName();
_subscriptionNameColumn = table.getPrimaryKey().get(1).getName();
_subscriptionColumn = table.getColumns().get(2).getName();
} | java | private void getColumnNames() {
TableMetadata table = _keyspace.getKeyspaceMetadata().getTable(CF_NAME);
_rowkeyColumn = table.getPrimaryKey().get(0).getName();
_subscriptionNameColumn = table.getPrimaryKey().get(1).getName();
_subscriptionColumn = table.getColumns().get(2).getName();
} | [
"private",
"void",
"getColumnNames",
"(",
")",
"{",
"TableMetadata",
"table",
"=",
"_keyspace",
".",
"getKeyspaceMetadata",
"(",
")",
".",
"getTable",
"(",
"CF_NAME",
")",
";",
"_rowkeyColumn",
"=",
"table",
".",
"getPrimaryKey",
"(",
")",
".",
"get",
"(",
... | Because of the way databus tables were created historically using Astyanax and Cassandra 1.2 there may be
inconsistency in the names of the CQL columns in the subscription table. To be safe read the table metadata
to get the column names. | [
"Because",
"of",
"the",
"way",
"databus",
"tables",
"were",
"created",
"historically",
"using",
"Astyanax",
"and",
"Cassandra",
"1",
".",
"2",
"there",
"may",
"be",
"inconsistency",
"in",
"the",
"names",
"of",
"the",
"CQL",
"columns",
"in",
"the",
"subscript... | 97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb | https://github.com/bazaarvoice/emodb/blob/97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb/databus/src/main/java/com/bazaarvoice/emodb/databus/db/cql/CqlSubscriptionDAO.java#L166-L171 | train |
bazaarvoice/emodb | table/src/main/java/com/bazaarvoice/emodb/table/db/tableset/BlockFileTableSet.java | BlockFileTableSet.loadTable | private int loadTable(long uuid)
throws IOException {
int bufferIndex = -1;
Set<Long> uuids = null;
// Always attempt to append to the last block first.
int blockIndex = _blocks.size() - 1;
TableBlock lastBlock = _blocks.get(blockIndex);
// Even though this is a while loop it will run at most twice: once if there is room in the current final
// block, and a second time if there wasn't and a new block needed to be allocated.
while (bufferIndex == -1) {
Pair<Integer, Set<Long>> bufferIndexAndUuuids = lastBlock.writeTable(uuid);
bufferIndex = bufferIndexAndUuuids.left;
if (bufferIndex == -1) {
blockIndex++;
lastBlock = new TableBlock(blockIndex * _blockSize);
_blocks.add(lastBlock);
} else {
uuids = bufferIndexAndUuuids.right;
}
}
int index = toIndex(blockIndex, bufferIndex);
// Map each UUID associated with the table to the table's index
for (Long tableUuid : uuids) {
_fileIndexByUuid.put(tableUuid, index);
}
return index;
} | java | private int loadTable(long uuid)
throws IOException {
int bufferIndex = -1;
Set<Long> uuids = null;
// Always attempt to append to the last block first.
int blockIndex = _blocks.size() - 1;
TableBlock lastBlock = _blocks.get(blockIndex);
// Even though this is a while loop it will run at most twice: once if there is room in the current final
// block, and a second time if there wasn't and a new block needed to be allocated.
while (bufferIndex == -1) {
Pair<Integer, Set<Long>> bufferIndexAndUuuids = lastBlock.writeTable(uuid);
bufferIndex = bufferIndexAndUuuids.left;
if (bufferIndex == -1) {
blockIndex++;
lastBlock = new TableBlock(blockIndex * _blockSize);
_blocks.add(lastBlock);
} else {
uuids = bufferIndexAndUuuids.right;
}
}
int index = toIndex(blockIndex, bufferIndex);
// Map each UUID associated with the table to the table's index
for (Long tableUuid : uuids) {
_fileIndexByUuid.put(tableUuid, index);
}
return index;
} | [
"private",
"int",
"loadTable",
"(",
"long",
"uuid",
")",
"throws",
"IOException",
"{",
"int",
"bufferIndex",
"=",
"-",
"1",
";",
"Set",
"<",
"Long",
">",
"uuids",
"=",
"null",
";",
"// Always attempt to append to the last block first.",
"int",
"blockIndex",
"=",... | Loads a table from the source and places it into the next available space in the table blocks.
Once the table is written it returns the index where the table is located for future reads. | [
"Loads",
"a",
"table",
"from",
"the",
"source",
"and",
"places",
"it",
"into",
"the",
"next",
"available",
"space",
"in",
"the",
"table",
"blocks",
".",
"Once",
"the",
"table",
"is",
"written",
"it",
"returns",
"the",
"index",
"where",
"the",
"table",
"i... | 97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb | https://github.com/bazaarvoice/emodb/blob/97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb/table/src/main/java/com/bazaarvoice/emodb/table/db/tableset/BlockFileTableSet.java#L100-L131 | train |
bazaarvoice/emodb | table/src/main/java/com/bazaarvoice/emodb/table/db/tableset/BlockFileTableSet.java | BlockFileTableSet.readTable | private Table readTable(int index) {
// Get the block
TableBlock block = _blocks.get(getBlock(index));
// Return the table located at the block offset
return block.getTable(getBlockOffset(index));
} | java | private Table readTable(int index) {
// Get the block
TableBlock block = _blocks.get(getBlock(index));
// Return the table located at the block offset
return block.getTable(getBlockOffset(index));
} | [
"private",
"Table",
"readTable",
"(",
"int",
"index",
")",
"{",
"// Get the block",
"TableBlock",
"block",
"=",
"_blocks",
".",
"get",
"(",
"getBlock",
"(",
"index",
")",
")",
";",
"// Return the table located at the block offset",
"return",
"block",
".",
"getTabl... | Reads the table located at the given index. | [
"Reads",
"the",
"table",
"located",
"at",
"the",
"given",
"index",
"."
] | 97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb | https://github.com/bazaarvoice/emodb/blob/97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb/table/src/main/java/com/bazaarvoice/emodb/table/db/tableset/BlockFileTableSet.java#L136-L141 | train |
bazaarvoice/emodb | table/src/main/java/com/bazaarvoice/emodb/table/db/tableset/BlockFileTableSet.java | BlockFileTableSet.ensureBufferAvailable | private void ensureBufferAvailable(TableBlock block) throws IOException {
if (!block.hasBuffer()) {
synchronized (this) {
if (!block.hasBuffer()) {
ByteBuffer buffer = getBuffer();
block.setBuffer(buffer);
}
}
}
} | java | private void ensureBufferAvailable(TableBlock block) throws IOException {
if (!block.hasBuffer()) {
synchronized (this) {
if (!block.hasBuffer()) {
ByteBuffer buffer = getBuffer();
block.setBuffer(buffer);
}
}
}
} | [
"private",
"void",
"ensureBufferAvailable",
"(",
"TableBlock",
"block",
")",
"throws",
"IOException",
"{",
"if",
"(",
"!",
"block",
".",
"hasBuffer",
"(",
")",
")",
"{",
"synchronized",
"(",
"this",
")",
"{",
"if",
"(",
"!",
"block",
".",
"hasBuffer",
"(... | Checks whether the given block has a buffer assigned to it. If not, it synchronously gets an available buffer
and assigns it to the block. | [
"Checks",
"whether",
"the",
"given",
"block",
"has",
"a",
"buffer",
"assigned",
"to",
"it",
".",
"If",
"not",
"it",
"synchronously",
"gets",
"an",
"available",
"buffer",
"and",
"assigns",
"it",
"to",
"the",
"block",
"."
] | 97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb | https://github.com/bazaarvoice/emodb/blob/97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb/table/src/main/java/com/bazaarvoice/emodb/table/db/tableset/BlockFileTableSet.java#L167-L176 | train |
bazaarvoice/emodb | databus/src/main/java/com/bazaarvoice/emodb/databus/core/DefaultDatabus.java | DefaultDatabus.toEvents | private List<Event> toEvents(Collection<Item> items) {
if (items.isEmpty()) {
return ImmutableList.of();
}
// Sort the items to match the order of their events in an attempt to get first-in-first-out.
return items.stream().sorted().map(Item::toEvent).collect(Collectors.toList());
} | java | private List<Event> toEvents(Collection<Item> items) {
if (items.isEmpty()) {
return ImmutableList.of();
}
// Sort the items to match the order of their events in an attempt to get first-in-first-out.
return items.stream().sorted().map(Item::toEvent).collect(Collectors.toList());
} | [
"private",
"List",
"<",
"Event",
">",
"toEvents",
"(",
"Collection",
"<",
"Item",
">",
"items",
")",
"{",
"if",
"(",
"items",
".",
"isEmpty",
"(",
")",
")",
"{",
"return",
"ImmutableList",
".",
"of",
"(",
")",
";",
"}",
"// Sort the items to match the or... | Converts a collection of Items to Events. | [
"Converts",
"a",
"collection",
"of",
"Items",
"to",
"Events",
"."
] | 97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb | https://github.com/bazaarvoice/emodb/blob/97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb/databus/src/main/java/com/bazaarvoice/emodb/databus/core/DefaultDatabus.java#L765-L772 | train |
bazaarvoice/emodb | databus/src/main/java/com/bazaarvoice/emodb/databus/core/DefaultDatabus.java | DefaultDatabus.unclaim | private void unclaim(String subscription, Collection<EventList> eventLists) {
List<String> eventIdsToUnclaim = Lists.newArrayList();
for (EventList unclaimEvents : eventLists) {
for (Pair<String, UUID> eventAndChangeId : unclaimEvents.getEventAndChangeIds()) {
eventIdsToUnclaim.add(eventAndChangeId.first());
}
}
_eventStore.renew(subscription, eventIdsToUnclaim, Duration.ZERO, false);
} | java | private void unclaim(String subscription, Collection<EventList> eventLists) {
List<String> eventIdsToUnclaim = Lists.newArrayList();
for (EventList unclaimEvents : eventLists) {
for (Pair<String, UUID> eventAndChangeId : unclaimEvents.getEventAndChangeIds()) {
eventIdsToUnclaim.add(eventAndChangeId.first());
}
}
_eventStore.renew(subscription, eventIdsToUnclaim, Duration.ZERO, false);
} | [
"private",
"void",
"unclaim",
"(",
"String",
"subscription",
",",
"Collection",
"<",
"EventList",
">",
"eventLists",
")",
"{",
"List",
"<",
"String",
">",
"eventIdsToUnclaim",
"=",
"Lists",
".",
"newArrayList",
"(",
")",
";",
"for",
"(",
"EventList",
"unclai... | Convenience method to unclaim all of the events from a collection of event lists. This is to unclaim excess
events when a padded poll returns more events than the requested limit. | [
"Convenience",
"method",
"to",
"unclaim",
"all",
"of",
"the",
"events",
"from",
"a",
"collection",
"of",
"event",
"lists",
".",
"This",
"is",
"to",
"unclaim",
"excess",
"events",
"when",
"a",
"padded",
"poll",
"returns",
"more",
"events",
"than",
"the",
"r... | 97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb | https://github.com/bazaarvoice/emodb/blob/97ec7671bc78b47fc2a1c11298c0c872bd5ec7fb/databus/src/main/java/com/bazaarvoice/emodb/databus/core/DefaultDatabus.java#L778-L787 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.